视图不显示控制器数组的内容

发布于 2024-11-28 23:42:44 字数 575 浏览 1 评论 0原文

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

    $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>

有什么想法吗?

I have a controller that pulls data from a model function and stores the data in an array:

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

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

The view simply take the array and iterates the values using a foreach loop and list items. The list items are appearing but not the text value of the array:

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

Any ideas why?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

桃扇骨 2024-12-05 23:42:44

一下吗

$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']
    );
}  

instead of

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

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

could you try

$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']
    );
}  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文