Welcome Guest, Not a member yet? Register   Sign In
--Is there a controller hierarchy ?
#1

[eluser]Unknown[/eluser]
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().
#2

[eluser]CodeOfficer[/eluser]
yep, you have to manually include it unfortunately
#3

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

[eluser]Unknown[/eluser]
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:
$this->someclass->some_function();

But still I cannot sub-class it like:

class SubClass extends Someclass {
// some logic here
}
#5

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




Theme © iAndrew 2016 - Forum software by © MyBB