• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Layout Engine

#1
[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.

#2
[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].

#3
[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

#4
[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!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.