【发布时间】:2020-07-06 14:52:42
【问题描述】:
我有这个对象和数组数据:
stdClass Object
(
[meta_title] => title
[meta_description] =>
[categories] => Array
(
[0] => stdClass Object
(
[name] => cat title
)
[1] => stdClass Object
(
[name] =>cat title 2
)
)
)
实际上,我需要使用foreach 方法打印categories name 。这个怎么打印?!
编辑:
在我的控制器中我有:
public function index()
{
helper('text');
$data = array(
'meta_title' => 'title',
'meta_description' => '',
'categories' => $this->postModel->getNewsCategories(),
);
return view('blog/index', array( 'categories' => (object)$data));
}
在视图中:
<?php foreach ($categories as $category) : ?>
<a href="#"><?php echo esc($category->name);?></a>
<?end foreach;?>
但我看到了这个错误:
Trying to get property 'name' of non-object
【问题讨论】:
-
你已经尝试过什么了吗?
-
@u_mulder:请看我的编辑