• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
--Is there a controller hierarchy ?

Hi I am a newbie to CI. I created a controller which extends the Controller:

class BaseSessionController extends Controller {
// some logic here

Then I tried to create another controller class which extends the BaseSessionController:

class SubController extends BaseSessionController {
// some logic here

These two controllers are in two different php files -- both in the controllers folder. It seems that BaseSessionController could not be recognized by SubController . I am wondering if I have to manually include the BaseSessionController script file in my SubController script, using require() or require_once().

yep, you have to manually include it unfortunately

[eluser]Matthew Pennell[/eluser]
If it's not being used as a 'real' controller (i.e. you're only sub-classing it), you could stick it in the /libraries folder - that way you can autoload it and won't have to require/include it.

I tried the library approach, but it can only be accessed through composition but not inheritance.

Specifically, I first created a script:

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

class Someclass {

function some_function()


Then put it into the library folder, and modified the autoload.php to auto-load it.

After that I can access it in other controllers through composition like:

But still I cannot sub-class it like:

class SubClass extends Someclass {
// some logic here

Yeah, I had wanted to do the same at one point and was only able to pull it off when I hardcoded the include.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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