如何处理Codeigniter模板? [英] How to Deal With Codeigniter Templates?

查看:128
本文介绍了如何处理Codeigniter模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对MVC很新,我最近发现了CodeIgniter。我还在学习每天,但一个问题是它的模板引擎。在CodeIgniter中创建模板的最好方法是什么?

I'm fairly new to MVC, and I've found CodeIgniter recently. I'm still learning everyday, but one problem is its template engine. What is the best way to create templates in CodeIgniter?

CakePHP自带的模板库,CodeIgniter有类似的功能吗?

CakePHP comes with its own template library, is there a similar feature in CodeIgniter?

推荐答案

与其他框架不同,CodeIgniter没有全局模板系统。

Unlike other frameworks CodeIgniter does not have a global template system. Each Controller controls it's own output independent of the system and views are FIFO unless otherwise specified.

例如,如果我们有一个全局标题:

For instance if we have a global header:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd" >
<html>
    <head>
        <title><?=$title?></title>
        <!-- Javascript -->
        <?=$javascript ?>
        <!-- Stylesheets -->
        <?=$css ?>
    </head>
    <body>
        <div id="header">
            <!-- Logos, menus, etc... -->
        </div>
        <div id="content">

和全局页脚:

        </div>
        <div id="footer">
            <!-- Copyright, sitemap, links, etc... -->
        </div>
    </body>
</html>

那么我们的控制器必须看起来像

then our controller would have to look like

<?php
class Welcome extends Controller {

    function index() {
        $data['title'] = 'My title';
        // Javascript, CSS, etc...

        $this->load->view('header', $data);

        $data = array();
        // Content view data
        $this->load->view('my_content_view', $data);

        $data = array();
        // Copyright, sitemap, links, etc...
        $this->load->view('footer', $data);
    }
}

还有其他组合,图书馆:

There are other combinations, but better solutions exist through user libraries like:

查看下面的注释

这篇关于如何处理Codeigniter模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆