【问题标题】:Load a view inside another view在另一个视图中加载视图
【发布时间】:2013-02-26 18:42:57
【问题描述】:

我使用 django 已经有一段时间了,我决定开始一个新项目,但这次在 Codeigniter 中,我曾经在我的视图中扩展模板文件并将内容放在 {% block content %} 块中,但它在 CodeIgniter 中看起来有所不同。

在 CodeIgniter 中我有类似的东西:

<?php
     $this->load->view('header');
     $this->load->view('form_add_customer');
     $this->load->view('footer');
?>

但是有没有办法让一个具有像这样的页眉、内容和页脚的唯一文件?

<html>
    <head><title>Test</title></head>
    <body>
        <div id="header">Welcome</div>
        <div id="content">
        </div>
        <div id="footer"> 2013 - Tectcom Telecom</div>
    </body>
</html>

并在内容 div 中放置一个带有表单的视图文件?

【问题讨论】:

    标签: codeigniter codeigniter-2


    【解决方案1】:

    像这样更新您的 html(布局)文件:

    <div id="content"><?php $this->load->view($content) ?></div>
    

    在你的控制器中,像这样调用视图:

    $view_data = array();
    $view_data['content'] = 'form_add_customer';
    $this->load->view('path/to/layout', $view_data);
    

    【讨论】:

      【解决方案2】:

      我过去曾在小型项目中成功使用过“Most Simple Template Library for CodeIgniter”。我相信它将提供您需要的功能,允许您在“模板”中使用占位符,您可以在控制器逻辑中进行更新。

      【讨论】:

        猜你喜欢
        • 2015-11-23
        • 2017-09-01
        • 1970-01-01
        • 1970-01-01
        • 2018-11-13
        • 1970-01-01
        • 2012-03-13
        • 2011-10-15
        • 1970-01-01
        相关资源
        最近更新 更多