【问题标题】:codeigniter dynamic data templatecodeigniter 动态数据模板
【发布时间】:2012-09-20 04:37:06
【问题描述】:

我在 view/include 有这个模板视图

<?php $this->load->view('include/header'); ?>
<?php $this->load->view($sidebar_column); ?>
<?php $this->load->view($result_column); ?>
<?php $this->load->view($footer_row); ?>
<?php $this->load->view('include/footer'); ?>

我在 view/include 处有 footer_row html

<div> this is footer row <?php echo $username ?></div>

然后我在控制器中调用 footer_row

$data['footer_row'] = 'include/footer_row';
$this->load->view('include/template',$data);

我的问题,footer_row 已登录用户信息,它出现在每个页面中。使用我使用的上述方法,我必须调用并检索每个控制器中的用户信息。我怎样才能使它可重复使用,所以我不需要重复自己。

【问题讨论】:

    标签: codeigniter templates


    【解决方案1】:

    可重用性来自对构造函数和父类的利用。看看我之前的回答:

    1. Header and Footer in CodeIgniter
    2. Constructor session validation for different functions

    【讨论】:

      【解决方案2】:

      您为什么不使用易于使用的模板库,而不是使用这种方法。我会推荐 Philsturgeons 模板库,但您可以使用更多符合您要求的模板库。

      威廉姆斯概念

      http://williamsconcepts.com/ci/codeigniter/libraries/template/

      菲尔·斯特金斯的

      http://philsturgeon.co.uk/demos/codeigniter-template/user_guide/

      最简单

      http://maestric.com/doc/php/codeigniter_template

      最后是 Binpresses 的

      http://www.binpress.com/app/codeigniter-template-library/223

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-12-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-05-20
        相关资源
        最近更新 更多