列表类别控制器 OpenCart 2 不起作用


Listing categories controller OpenCart 2 not working

我正在尝试通过自定义控制器和自定义模板在OpenCart中列出类别名称和图像,但此代码不起作用

控制器

文件目录''控制器''设计器''列表.php

class ControllerDesignerListing extends Controller {
public function index(){
 $this->document->setTitle("Listign Designers ");
 if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/designer/listing.tpl')) {
     $this->template = $this->config->get('config_template') . '/template/designer/listing.tpl';
 } else {
     $this->template = 'default/template/designer/listing.tpl';
 }

 $this->load->model('catalog/category');
 $this->data['categories'] = array();
 foreach ($this->model_catalog_category->getCategories(array()) as $category) {
     $this->data['categories'][] = array(
         'category_id' => $category['category_id'],
         'name'        => $category['name']
     );
 }

 $data['column_left'] = $this->load->controller('common/column_left');
 $data['column_right'] = $this->load->controller('common/column_right');
 $data['content_top'] = $this->load->controller('common/content_top');
 $data['content_bottom'] = $this->load->controller('common/content_bottom');
 $data['footer'] = $this->load->controller('common/footer');
 $data['header'] = $this->load->controller('common/header');


 // call the "View" to render the output
 $this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/designer/listing.tpl', $data));
 }
}

那就是模板文件

      <?php if($categories) { ?>
            <?php foreach  ($categories as $category) { ?>
            <div class="col-md-3 col-sm-4 col-xs-6"><!--item-->
                <div class="item">
                    <div class="img-wrap"><img src="imgs/list-image.jpg" alt=""></div>
                    <div class="content">
                        <div class="flag"><img src="imgs/flag-place.jpg" alt=""></div><a href="#">
                            <h4><?php echo $category['name']; ?></h4></a>
                        <h5>tokyo, japan</h5><a href="#" class="line">FOLLOW</a>
                    </div>
        </div>
    </div>
    <?php } ?>
    <?php } ?>
这里有

一些愚蠢的错误,

catalog'controller'designer'listing.php中查找$this->data['categories']并替换为$data['categories']

这将工作.

无论何时将 opencart 文件从版本 1.5.x.x 升级到 2.x.x.x ,请始终记住这一点,这是 opencart 版本中的主要变化2.x.x.x