Search code examples
codeignitercontrollerhierarchysubdirectoryrequire-once

Codeigniter controller in subfolder extends outside one


Is it possible a controller inside a subfolder, lets call it 'category', extends from a controller from the parent folder?

Example:

  • application_controller.php in the controller folder
  • category in the folder controller/category

It keeps me showing the error

require_once(../application_controller.php) [function.require-once]: failed to open stream: No such file or directory

Is there some trick i'm missing to do that?

Thanks in advance
Elkas


Solution

  • You're technically executing in a wierd scope because of how the controllers are loaded up.

    require_once(APPPATH.'controllers/application_controller.php');
    

    This is what you're looking for.

    APPPATH will always point to your application/ folder.