CodeIgniter Forums
What's the practical way to load header and footer - 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: What's the practical way to load header and footer (/showthread.php?tid=9007)

Pages: 1 2


What's the practical way to load header and footer - El Forum - 06-22-2008

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


What's the practical way to load header and footer - El Forum - 06-22-2008

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


What's the practical way to load header and footer - El Forum - 06-23-2008

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


What's the practical way to load header and footer - El Forum - 06-23-2008

[eluser]AgentPhoenix[/eluser]
I've been using the Layout library which has been pretty awesome to date.