Question

I'm having a bit of confusion in attempting to retroactively create a new base controller for my project. If I'm not mistaken, all I need to do is create a file in application/libraries called MY_baseController.php containing the following:

class baseController extends Template_Controller
{
  public function __construct()
  {
    parent::__construct();
  }
}

And then rewrite my other controllers to extend baseController instead of Template_Controller:

class Frontpage_Controller extends Template_Controller

to

class Frontpage_Controller extends baseController

Yet when I do this, accessing the Frontpage_Controller alerts me that:

Class 'baseController' not found...

What am I missing here?

Was it helpful?

Solution

After some fiddling, I think the following is my solution...

Move MY_baseController.php from application/libraries and into application/controllers. Rename it to base.php and change the following line:

class baseController extends Template_Controller

into

class Base_Controller extends Template_Controller

Now within your Frontpage Controller, extend Base_Controller instead of baseController.

OTHER TIPS

Make sure you follow Kohana Conventions to make sure everything auto-loads properly! There are similar ones in relation to Models Helpers and Libraries.

Also if you want to keep your main application controller folder clean I would suggest making a Kohana module just for your application and put all your template and misc extension controllers there to keep them separate from your main controllers.

Just don't forget to add the module to your config file!

I know this is an old question, but I thought I'd put in a word. You just need to remove the MY_ prefix from the file name as you only really need it when extending a class suffixed with _Core in the system folder. For example, the file for

class Controller extends Controller_Core

would be named MY_Controller.php.

In this case, just naming the file baseController.php and putting it in the libraries folder would work.

No offense, but I had to bang my head on my computer to get it working with Kohana 3.1. I finally figured out that the syntax to extend Template Controller should be:

class Controller_Base extends Controller_Template
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top