我正在尝试显示从我的控制器传递到视图的数组值,但是 php 正在选择它打印的值。
我希望输出的值是 $cat['category_image'] 但是当我访问该页面时出现未定义的索引错误。
我正在使用 Codeigniter MVC,这是代码......
<?php foreach ($categories as $cat):?>
<li>
<a href="<?=site_url('category/'.str_replace(" ", "-", strtolower($cat['category_name'])))?>">
<div><?=$cat['category_name']?></div>
<img src="<?=CDN_IMAGES . $cat['category_image']?>" width="210" height="315" border="0" />
</a>
</li>
<?php endforeach; ?>
如果我从控制器执行数组值的 print_r,我会得到这个......
Array
(
[catagories] => Array
(
[0] => Array
(
[category_id] => 62
[category_status] => SHOW
[category_icon] =>
[category_image] => cats\special.jpg
[language_id] => en
[category_name] => Specialties
)
[1] => Array
(
[category_id] => 72
[category_status] => SHOW
[category_icon] =>
[category_image] => cats\white.jpg
[language_id] => en
[category_name] => White wine
)
[2] => Array
(
[category_id] => 82
[category_status] => SHOW
[category_icon] =>
[category_image] => cats\rose.jpg
[language_id] => en
[category_name] => Rose
)
[3] => Array
(
[category_id] => 92
[category_status] => SHOW
[category_icon] =>
[category_image] => cats\red.jpg
[language_id] => en
[category_name] => Red Wine
)
)
)
类别名称和 ID 工作正常,但其他一切都会引发未定义的错误,有人可以帮我解决这个问题吗?非常感谢。