douzhong3038 2018-03-22 09:07
浏览 38
已采纳

如何构建菜单“视图”并使其在CodeIgniter模板分析器中循环?

My database:

+----+-------+-------+
| id | slug  | text  |
+----+-------+-------+
| 1  | link1 | text1 |
| 2  | link2 | text2 |
| 3  | link3 | text3 |
+----+-------+-------+

My array (queried from database):

Array
(
    [0] => Array
        (
            [id] => 1
            [slug] => link1
            [text] => text1
        )

    [1] => Array
        (
            [id] => 2
            [slug] => link2
            [text] => text2
        )

    [2] => Array
        (
            [id] => 3
            [slug] => link3
            [text] => text3
        )

I want to write my view like this but I can't get it to work in a loop. (I sent the array for parsing already).

<ul>
{xxxxx}
    <li><a href="{slug}">{text}</a></li>
{/xxxxx}
</ul>
  • 写回答

2条回答 默认 最新

  • douye9175 2018-03-22 09:17
    关注

    You can save your array in a variable like:

    $data['blogs'] = $my_result_array_from_model;
    

    Send the data to view:

    $this->parser->parse('blog_template', $data);
    

    Then, in your view,

    <ul>
        {blogs}
            <li><a href="{slug}">{text}</a></li>
        {/blogs}
    </ul>
    

    For reference: Check out Official CI Documentation

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM