列表类别控制器 OpenCart 2 不工作
Listing categories controller OpenCart 2 not working
我正在尝试通过自定义控制器和自定义模板在 OpenCart 中列出类别名称和图像,但此代码无效
控制器文件catalog\controller\designer\listing.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
[=16 中的主要更改=]
我正在尝试通过自定义控制器和自定义模板在 OpenCart 中列出类别名称和图像,但此代码无效
控制器文件catalog\controller\designer\listing.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
[=16 中的主要更改=]