在catalog/controller/module/latest.php
, 之前$this->data['products'][] = array(
添加:
$categories = $this->model_catalog_product->getCategories($result['product_id']);
if($categories){
$categories_info = $this->model_catalog_category->getCategory($categories[0]['category_id']);
$category_title = $categories_info['name'];
}else{
$category_title = '';
}
更新$this->data['products'][]
数组如下:
$this->data['products'][] = array(
'product_id' => $result['product_id'],
'category_title' => $category_title,
'thumb' => $image,
'name' => $result['name'],
'price' => $price,
'special' => $special,
'rating' => $rating,
'reviews' => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
'href' => $this->url->link('product/product', 'product_id=' . $result['product_id']),
);
现在在 中latest.tpl
,您将获得类别标题为$product['category_title']
。
附加信息: - 模型函数应在控制器中调用。控制器中定义的变量$this->data['variable_name']
可以在模板文件中以$variable_name
.
祝你今天过得愉快 !!