• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Best way to have multiple parent controllers

#11
[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.

#12
[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');
        }
    
}


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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