• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What's the practical way to load header and footer

[quote author="Armchair Samurai" date="1213001338"]The basic one I use for simple sites is to have a template view file which is set up something like this:
/* The view file: template.php */

$this->load->view('includes/'.empty($header) ? 'header' : $header);
$this->load->view('includes/'.empty($footer) ? 'footer' : $footer);

Then just call the content from the controller:
/* In your a controller function */

    'content' => 'myview',
    'var' => 'foo',
    'other_var' => 'bar',

This is awesome, thanks.

Have to say that I had same issue when I started with CI (two weeks ago). I came to conclusion that loading headers and footers via a master view made the most sense and was delighted to see that this is what most of the replies in this thread suggest. So now I answer this question with a question (bad me, bad):

Quote:How would one go about getting the User Guide updated so that this is obvious to people adopting the framework for the first time?

A small section in the Views page would have saved me some time. It would also stop others from going down the evil path of dumping the view composition into the controllers as the guide suggests at the moment.

[eluser]RaZoR LeGaCy[/eluser]
[quote author="Bramme" date="1213012624"]Same as armchair samurai... I create a masterviewfile like this

//master view - index.php
And then from my controller

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

Seeing as your data gets transferred to your 'subviews' automatically, it works as a charm!

This is the best way that I know of and everyone should do it like this.

I've been using the Layout library which has been pretty awesome to date.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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