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


I'm wondering what is the most practical way to load a header and a footer.

I know I can do:


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.

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:
/* 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',

I always do:




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!

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.

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

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:
$this->data['pagvars']['contentview'] = 'name_of_template';
$this->load->view('template_main', $this->data);

Now, in the template I load this specified template, if it exists:
if (isset($pagvars['contentview']) && file_exists($pagvars['contentview'] . '.php')) {
    // Contentview exists, so let's load it
    require_once($pagvars['contentview'] . '.php');
else {
    // Contentview is not set or does not exist
    show_error ('Problem loading contentview');

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

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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