CodeIgniter Forums
Best way to have multiple parent controllers - 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: Best way to have multiple parent controllers (/showthread.php?tid=18326)

Pages: 1 2


Best way to have multiple parent controllers - El Forum - 05-03-2009

[eluser]wiredesignz[/eluser]
You should also seriously consider Rick Jolly's idea using __autoload() if you are developing under PHP5.

This would prevent including unnecessary base classes.


Best way to have multiple parent controllers - El Forum - 05-03-2009

[eluser]opel[/eluser]
Ok thanks everyone for their help, for anyone that stumbles across this here is my all my code to get multiple controllers.

At the end of config.php
Code:
/*
|--------------------------------------------------------------------------
| AUTOLOAD CONTROLLERS
|--------------------------------------------------------------------------
|
*/

function __autoload($class)
{
    if(strstr($class,'_Controller'))
    {
        include_once(APPPATH . 'libraries/' . $class . EXT);
    }
}

In libraries/MY_Controller.php (Variables can be passed to all extended controllers)

Code:
class MY_Controller extends Controller
{
    
    function MY_Controller()
    {
        parent::Controller();
        }
}
Code:
<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class Base_controller extends Controller
{

    public $navigation = NULL;
    public $footer = NULL;

    function Base_controller()
    {
        parent::Controller();
        $this->navigation();
        $this->footercopy();
    }


    
        function navigation()
        {
            $this->navigation['navigation'] = array("Home", "Test", "contact");
            $this->data['frontend_navigation'] = $this->load->view ('common/frontend_navigation', $this->navigation, TRUE);
        }
    
    
        function footercopy()
        {
            $this->data['footer'] = '© '.date('Y').' '.$this->config->item('project');
        }
    
}