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]Michael Wales[/eluser]
There is a controller hierarchy if you extend the controller (by placing MY_Controller.php in applications/controllers) - you can define the prefix in config.php.

Otherwise, simply require them and everything will be okay.
#3

[eluser]esra[/eluser]
It should work if you do this:

Code:
<?php

require(path/to/file/BaseSessionController.php);

class SubController extends BaseSessionController
{
    ...
}
?>

The alternate solution is to place the BaseSessionController code is a class called MY_Controller stored in application/libraries/. CI will automatically load the MY_Controller class. The disadvantage of this solution is that you would have only one base controller. By using the above solution, you can use any number of base controllers.




Theme © iAndrew 2016 - Forum software by © MyBB