Because Yii doesn’t allow multiple locations for controllers (ie: it only looks in protected/controllers) i need a way to create controllers and also to extend those controllers so that i can override them.
The idea is that i would have an application and who ever uses it, doesn’t have to modify the base controllers, instead, they will extend the existing ones and override custom functionality.
I thought maybe doing something like the following structure:
--protected
---base-controllers
------BaseSiteController.php
---controllers
------SiteController.php
---models
And the controllers structure would be like:
// BaseSiteController.php
class BaseSiteController extends CController{
public function actionIndex(){}
public function actionView(){}
public function actionSomethingElse(){}
}
// SiteController.php
Yii::import('application.base-controllers.*');
class SiteController extends BaseSiteController{
}
Now as you see, the SiteController is just an empty class, that extends the functionality of BaseSiteController and when the controller will be accesed it will call the parent class implementation.
Overriding an action of the base controller in would be as easy as:
Yii::import('application.base-controllers.*');
class SiteController extends BaseSiteController{
public function actionIndex(){
//run here the new index for the site controller.
}
}
Now this all sounds very good till now, at least for me.
The issue here is that, i don’t want by default to create controllers in the controllers folder for each of the base controllers, basically i just want to have the base-controllers folder populated with the application controllers and in the controllers folder to add controllers only if i need to extend the functionality of one of the base controllers.
The issue is, that Yii will look in the controllers folder and of course that will be empty resulting in 404 errors for the requested actions, and i need a way to avoid that.
Any suggestion on how to do it ?
Any other ideas on how i could accomplish this task in any other way ?