• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dynamic Footer problem

#2
[eluser]missionsix[/eluser]
I've had a similar problem.

All my pages are wrapped with similar header / footers. So calling those views on every controller page seemed like a lot of code duplication.


So what I did was create a Parent controller that all my other controllers would extend. Then I created 1 method called Display that would load the header / footer views, or any other 'global' view files and then spit everything out into a container view.


Example: Public_Controller.php
Code:
<?php   if (!defined('BASEPATH')) exit('No direct script access allowed');

class Public_Controller extends Controller {

    public $container;
    public $data = array();
    
    public function Public_Controller() {
        parent::Controller();
        $this->container = 'container';
    }
    
    private function _prepare() {
        // Here I assign global data, like userinfo, ad management, ect...
        [...]
    }
    
    public function display($data = array()) {
        
        $this->data = array_merge($this->data, $data);
        
                // do any global data preparation
        $this->_prepare();
        
        $this->data['header'] = $this->load->view('includes/header', $this->data, true);
        $this->data['footer'] = $this->load->view('includes/footer', $this->data, true);
        
        $this->load->view($this->container, $this->data);
    }
    
}


?>

And then in my other controllers I do something like this:

Code:
<?php   if (!defined('BASEPATH')) exit('No direct script access allowed');

include_once 'public_controller.php';

class Front extends Public_Controller {
    
    public function __construct()
    {
        parent::Public_Controller();
        [...]
    }

    public function index() {
      // do index page

      $this->display();
    }

}


Messages In This Thread
Dynamic Footer problem - by El Forum - 09-02-2008, 01:04 PM
Dynamic Footer problem - by El Forum - 09-02-2008, 04:28 PM
Dynamic Footer problem - by El Forum - 09-02-2008, 06:56 PM
Dynamic Footer problem - by El Forum - 09-02-2008, 07:34 PM
Dynamic Footer problem - by El Forum - 09-02-2008, 08:08 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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