i hate repetitive coding

hi anybody

i developed an rbam module and i want to manage the authorization in my project


i dont like to write "Yii::app()->authManager->checkAccess()" in all of my actions

i want to have a method that run before any action, and in this function write these codes:

public function x($controller , $action){

$authItemName = $controller . $action;

return (Yii::app()->authManager->checkAccess($authItemName , Yii:app()->user->id));


how i can do it?

how i can force x method to run before any action?

Action filters:


method beforeAction in CController, returning true to allow, false to deny, use in a base Controller (like Controller) and extend all your controllers from this base controller

tanks mr gustavo


beforeAction has $action parameter.

so i think that using it is equal to writing "if Yii::app()->authManager->checkAccess(){}" at first line of each action.

i want to have a method that run before all actions . not specific to an action.

excuse me for my weak english.


beforeAction is an event triggered before any action, and you get the $action parameter to know details of the action to be executed, like its id (name)

therefore, you can use for your purposes the way you want (it will be executed before any action)