Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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 comes with its own template library, is there a similar feature in CodeIgniter?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
233 views
Welcome To Ask or Share your Answers For Others

1 Answer

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">

and a global footer:

        </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:

See Comments Below


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...