Mutliple Controllers

#1
[eluser]echoDreamz[/eluser]
I am looking to load multiple controllers into CI.

Basically it looks like so...

Main_Site_Controller --> Base_Controller --> CI Controller

Problem is right now I can only do
Base_Controller -> CI Controller

Reason for this is because I have the Base_Controller which extends the CI_Controller, it provides base functionality for all sites that I do, some custom items that I have.

The Main_Site_Controller is really custom to each site that I do, not all, but most have different items that I need loaded without editing my base_controller.

Please help me out on this one cause so far I have not found a solution to this.

#2
[eluser]Michael Wales[/eluser]
Seems like a whole lot of abstraction and I can't envision a scenario in which this would be beneficial. Regardless, if your config.php was setup to autoload the prefix 'Main_Site_':

libraries/Base_Controller.php
Code:
<?php
class Base_Controller extends Controller {
  function __construct() {
    parent::Controller();
  }
}

libraries/Main_Site_Controller.php
Code:
require('./Base_Controller.php');

class Main_Site_Controller extends Base_Controller{
  function __construct() {
    parent::Base_Controller();
  }
}


controllers/users.php
Code:
// Finally we get to a controller that is callable by users
class Users extends Main_Site_Controller {
  function __construct() {
    parent::Main_Site_Controller();
  }

  function index() { }
}

#3
[eluser]echoDreamz[/eluser]
Thanks,

I was looking for a more transparent solution with the use of includes on each and every controller.

Doing some editing on load_class() method in common.php resolved this for me.

I have my own controllers, helpers, and libraries that are based on my companies name as the prefix, and also use libraries, helpers etc that are loosely based on the clients domain name.

Also created my own loader and overwrote helper(), _ci_load_class(), and _ci_init_class() to take subclass_prefix as an array so I can pass multiple prefix names.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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