视图不显示控制器阵列的内容

时间:2011-08-10 10:08:38

标签: php opencart

我有一个控制器,它从模型函数中提取数据并将数据存储在一个数组中:

    $row = $this->model_catalog_manufacturer->getAllManufacturers();

    $this->data['manufacturer']= array(
        'manufacturer_id'    => $row['manufacturer_id'],
        'name'   => $row['name'],
        'image'       => $row['image']
    );  

视图只需获取数组并使用foreach循环和列表项迭代值。列表项出现但不是数组的文本值:

<ul>
<?php foreach ($manufacturer as $manuf) {?>
<li><?php echo $manuf['name'];?></li>
<?php }?>
</ul>

任何想法为什么?

1 个答案:

答案 0 :(得分:0)

而不是

$row = $this->model_catalog_manufacturer->getAllManufacturers();

    $this->data['manufacturer']= array(
        'manufacturer_id'    => $row['manufacturer_id'],
        'name'   => $row['name'],
        'image'       => $row['image']
    );  
你可以试试吗

$rows = $this->model_catalog_manufacturer->getAllManufacturers();
foreach($rows as $row){
    $this->data['manufacturer'][]= array(
        'manufacturer_id'    => $row['manufacturer_id'],
        'name'   => $row['name'],
        'image'       => $row['image']
    );
}