php - CodeIgniter 和 Smarty

标签 php codeigniter smarty

我有关联数组:

型号

public function selectArticle(){
    $sql = $this->db->query("SELECT * FROM articles");
    return $sql->result_array();
}

Controller

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}  

如何获取模板中的字段?
现在:article.fild - 不起作用

最佳答案

删除$article,必须使用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}

关于php - CodeIgniter 和 Smarty,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8669989/

相关文章:

php - 2 循环填充的数据数组,如何将数据转为插入查询

php - 如何在 Laravel 中获取选择值

php - 需要使用 PayPal 进行用户注册

php - 显示类别和子类别的查询

php - 使用变量设置背景 URL - 我做错了什么?

php - 使用 codeigniter 中的连接事件记录获取数据库字段的总和

php - MySQL 搜索结果 - 按相关性排序

php - 如何使用 <select> 选项将多个项目发布到 mysql

php - 使用 php 和 smarty 以水平方式显示数组数据

聪明人 : round up to decimal