您好我想自定义功能模块,通过管理员显示类别而不是特色模块
当我选择类别时它会显示类别产品什么是控制器的代码,它将类别n赋予产品数组到该类别
下面是类别选择输入的视图代码
<td><select name="category_id">
<?php foreach($categories as $category) { ?>
<option value="<?php echo $category['category_id'];?>"><?php echo $category['name'];?></option>
<?php } ?>
</select>
答案 0 :(得分:-1)
$categories = $this->model_catalog_product->getProductCategories(
$this->request->get['product_id']);
foreach($categories as $category_id) {
// do something
}
将getProductCategories
功能添加到model/catalog/product.php
public function getProductCategories($product_id) {
$product_category_data = array();
$query = $this->db->query("SELECT * FROM " . DB_PREFIX .
"product_to_category WHERE product_id = '" . (int)$product_id . "'");
foreach ($query->rows as $result) {
$product_category_data[] = $result['category_id'];
}
return $product_category_data;
}