Alex Rivera | Logout

Best Practices: What's the Best Way for Constructing Headers and Footers?

Asked 2008-10-07T01:01:40.603
19

What's the best way for constructing headers, and footers? Should you call it all from the controller, or include it from the view file? I'm using CodeIgniter, and I'm wanting to know what's the best practice for this. Loading all the included view files from the controller, like this?

class Page extends Controller {

   function index()
   {
      $data['page_title'] = 'Your title';
      $this->load->view('header');
      $this->load->view('menu');
      $this->load->view('content', $data);
      $this->load->view('footer');
   }

}

or calling the single view file, and calling the header and footer views from there:

//controller file    
class Page extends Controller {

   function index()
   {
      $data['page_title'] = 'Your title';
      $this->load->view('content', $data);

   }

}

//view file

<?php $this->load->view('header'); ?>

<p>The data from the controller</p>

<?php $this->load->view('footer'); ?>

I've seen it done both ways, but want to choose now before I go too far down a path.

Edit
Report

1 Answer

4

I think the first way you are doing it is cleaner. Simply from a point of view of knowledge that is going to be rendered. Rather than having to enter the view file to find the rest.

answered 2008-10-07T03:48:17.537

Your Answer