Equivalent Of App_Controller, App_Model On Yii

Learning the ropes of Yii.

On cakephp, they have this app_controller, app_model files before they load other controllers. I was wondering, if there is an equivalent on Yii.

On cake, they have this beforeFilter() as well that we can add up on app_controller, to set logic settings before anything else. I found out that Yii has beforeAction().


My understanding is it will be placed on each controller, is there a way to add it like a global method so, I won’t be adding it on all controller?

Thanks. Sorry, starting newbie on Yii.

Welcome to the forum

Add beforeAction method to "base" controller (e.g. protected/components/Controller.php) from which all other Controllers should inherit from.

Thanks. Worked perfectly.

I just like to note that you still need to do on every controller.

public function beforeAction() {



If you want to inherit some settings from the parent controller.

You can also take a look at CApplication::onBeginRequest.

I actually had an issue when I implemented this.

The methods on the site controllers are not being read.



public function beforeAction() {

	echo "Component, Controller";



public function beforeAction() {



Like on the SiteController, actionIndex()

It won’t be read anymore. Did I missed something?


Got it, the parent should return true.

protected function beforeAction($action) 


    return true; 


See: http://www.yiiframework.com/doc/api/1.1/CController#beforeAction-detail