我有关联数组:
模型
public function selectArticle(){
$sql = $this->db->query("SELECT * FROM articles");
return $sql->result_array();
}
控制器
public function index(){
$data['articles'] = $this->article->selectArticle();
$this->parser->parse('index.tpl', $data);
}
模板
{foreach from = $articles item = $article}
<tr>
<td width="30%">{$article.title}</td>
<td width="30%">
<a href="{$article.link}" target="_blank">http://example.net</a>
</td>
<td width="20%">{$article.size}</td>
<td width="20%">{$article.count}</td>
</tr>
{/foreach}
如何在模板中获得fild?
现在:article.fild - 不工作
答案 0 :(得分:3)
删除 $ article ,必须使用文章
{foreach from = $ articles item = $ article }
试用此代码:
{foreach from=$articles item=article}
<tr>
<td width="30%">{$article.title}</td>
<td width="30%"><a href="{$article.link}" target="_blank">http://example.net</a></td>
<td width="20%">{$article.size}</td>
<td width="20%">{$article.count}</td>
</tr>
{/foreach}