What's the practical way to load header and footer |
[eluser]EEssam[/eluser]
Hello, I'm wondering what is the most practical way to load a header and a footer. I know I can do: $this->load->view('header'); $this->load->view('myview'); $this->load->view('footer'); But I just don't see how I should call this in almost each function in my controller classes. Please advise.
[eluser]Gavin Blair[/eluser]
I start every view with <?php include 'header.php'; ?> and end each view with <?php include 'footer.php; ?> and everything else goes in between.
[eluser]EEssam[/eluser]
I found this method used by scaffolding: <? $this->load->view('header') ?> Not sure if it's the best.
[eluser]Armchair Samurai[/eluser]
The basic one I use for simple sites is to have a template view file which is set up something like this: Code: <?php Code: /* In your a controller function */
[eluser]stuffradio[/eluser]
I always do: Code: <?php
[eluser]Bramme[/eluser]
Same as armchair samurai... I create a masterviewfile like this Code: <?php Code: $this->data['page'] = 'somepage'; Seeing as your data gets transferred to your 'subviews' automatically, it works as a charm! [/code]
[eluser]xwero[/eluser]
I tend to use the template inheritance helper. It make the load->view more meaningful and other people can trace master pages by only looking at view files.
[eluser]tjmthome[/eluser]
yes, I agree with Bramme, i found the easyest way is a 'masterview' page (yes i know this maybe breaks a little MVC) but is practical
[eluser]JoostV[/eluser]
I use one master template from which I include header, footer, navbar, and so on. I always seem to have one content template that has to be loaded dynamically. I set this in the controller, before I load the main template, like so: Code: $this->data['pagvars']['contentview'] = 'name_of_template'; Now, in the template I load this specified template, if it exists: Code: if (isset($pagvars['contentview']) && file_exists($pagvars['contentview'] . '.php')) {
[eluser]mattalexx[/eluser]
[quote author="tjmthome" date="1213046956"]yes, I agree with Bramme, i found the easyest way is a 'masterview' page (yes i know this maybe breaks a little MVC) but is practical[/quote] How does that break MVC? |
Welcome Guest, Not a member yet? Register Sign In |