CodeIgniter Forums
Layout Engine - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Layout Engine (/showthread.php?tid=22330)



Layout Engine - El Forum - 09-05-2009

[eluser]Unknown[/eluser]
Hello.

I'm new in CodeIgniter's world.

I wanna ask for experienced CodeIgniter's users what layout engine they like to use.

Also I wanna ask if I really have to load views for every controller function. For example:
Code:
class Blog extends Controller {

    function index() {
        $this->load->view("header");

        $this->load->view("blog/view_posts");

        $this->load->view("footer");
    }

    function view_post($post_id) {
        $this->load->view("header");

        $this->load->view("blog/view_post", array("post_id" => $post_id));

        $this->load->view("footer");
    }

    function add_post() {
        $this->load->view("header");

        $this->load->view("blog/add_post");

        $this->load->view("footer");
    }

}
There is a better way? What method for loading views do you use for your projects?

Thanks.


Layout Engine - El Forum - 09-05-2009

[eluser]jedd[/eluser]
Hi Heliton,

Quote:Also I wanna ask if I really have to load views for every controller function.

You could load your header & footer views into variables, in the constructor of your Blag class - and then just echo them out in your final view.

Alternatively you can extrapolate that approach up another level by extending the core controller (lookup MY_Controller in the user guide).

I've rambled about this at some length [url="http://codeigniter.com/wiki/Header_and_Footer_and_Menu_on_every_page_-_jedd/"]in the wiki[/url].


Layout Engine - El Forum - 09-08-2009

[eluser]Vicente Russo[/eluser]
I personaly use only one view, and inside that view, I use the include('includes/header.php') and include('includes/footer.php').

But you can add layout support like RubyOnRails into CodeIgniter


Layout Engine - El Forum - 09-09-2009

[eluser]helmutbjorg[/eluser]
/controllers/test.php
Code:
function index() {

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

}

function example() {

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

}


/views/template.php
Code:
<html>
<head>
<title>My Template</title>
</head>
<body>
<h1>My Template</h1>

&lt;?php this->load->view($view); ?&gt;

&lt;/body&gt;
&lt;/html&gt;

/views/index.php
Code:
<p>This is custom index content</p>

/views/example.php
Code:
<p>And this is the example page content</p>


Pretty easy really eh!