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

#11
[eluser]mattalexx[/eluser]
[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:
Code:
<?php
/* The view file: template.php */

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

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

$this->load->vars(array(
    'content' => 'myview',
    'var' => 'foo',
    'other_var' => 'bar',
));
$this->load->view('template');
[/quote]

This is awesome, thanks.

#12
[eluser]Unknown[/eluser]
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.

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

Code:
<?php
//master view - index.php
$this->load->view('header');
$this->load->view($page);
$this->load->view('footer');
?>
And then from my controller

Code:
$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!
[/code][/quote]

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

#14
[eluser]AgentPhoenix[/eluser]
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.