我目前正在使用Latte做一些事情。我不明白的是,如何在带有模板变量的查询上使用foreach循环。我下面的代码总是以Trying to get property of non-object格式返回
$query = $this->db->query("SELECT id FROM table");
$array = array();
while($fetch = $query->fetch_array()){
$array = $fetch;
}
$Template["qclisting"] = $array;和模板代码
{foreach $qclisting as $item}
<a href="" class="list-group-item clearfix">
<span class="clear">
<span>{$item->id}</span>
</span>
</a>
{/foreach}发布于 2016-09-21 00:59:56
在模板中,使用
$item['id']...instead of...
$item->id并且,从代码的第4行删除[]:
$array = $fetch;更新:
如果您只看到输出的第一行,那么我就错了。在代码的第四行重新添加[]:
$array[] = $fetch;https://stackoverflow.com/questions/39599586
复制相似问题