【问题标题】:How to manage multi template in codeigniter?如何在codeigniter中管理多模板?
【发布时间】:2012-11-24 17:31:51
【问题描述】:

我正在开发支持 codeigniter 模板的网站。就像 joomla / drupal 我该怎么做?我当前的站点结构是每个控制器都有自己的模板。页眉和页脚模板是单独的文件。谁能告诉我该怎么做?

【问题讨论】:

  • 这个网站是针对特定的编程问题,而不是一般的教程。

标签: codeigniter


【解决方案1】:

看看 Phil Sturgeon 的 CodeIgniter-Template。

CodeIgniter-Template 是一个可以帮助您构建的模板库 CodeIgniter 的复杂视图。它具有与主题和 模块并帮助添加您的标题、元数据、面包屑和部分 意见。

https://github.com/philsturgeon/codeigniter-template

【讨论】:

  • 需要 CI 3.0 的东西
【解决方案2】:

这是在 codeigniter 中创建模板的一种简单灵活的方法 (通过杰弗里方式,nettuts) 所以在你的控制器中,在方法的最后......

 $data['content01'] = 'aboutus';
 $data['content02'] = 'contactform';
 $this->load->view( 'template_web', $data );

在你的views文件夹下,在这个例子中文件被称为:template_web.php

        <?php 
        // sample header
            // you can also use to load nav bars, etc 
        $this->load->view('header'); 

            // check if unique content has been passed to template
            // you can have as many of these as you need
        if(isset($content01))
        $this->load->view($content01);

        if(isset($content02))
        $this->load->view($content02);

        if(isset($content03))
        $this->load->view($content03);

        // sample for a default footer
        $this->load->view('footer'); 

所以我们正在加载一个默认的页眉和页脚,然后内容来自控制器

很酷的是,如果需要,您可以使用相同的设置从控制器中快速调用不同的模板

 $data['content01'] = 'contactform';
 $this->load->view( 'template_admin', $data );

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-30
    • 2010-11-05
    • 2012-08-20
    • 2012-05-01
    • 1970-01-01
    • 2018-09-05
    • 1970-01-01
    相关资源
    最近更新 更多