HELP! How to add actions in the process of handing an URL.

When we enter an URL in the address bar, and press key "Enter", there is sth to handle this request. If the action is opened to anonymous users, the requested webpage will be shown. If the action is opened to authorized users, user will be redirected to log in page.

Now I want to add some actions during this process: after pressing “Enter” and before displaying the correct page. Where should I add code? I don’t want to modify controllers.

Thanks!

Well, I think controller is best place, but that also depends what you want to archieve.

You can use events:

http://www.yiiframework.com/wiki/44/

I solved this problem. I override beforeAction() method in Controller, which extends CController. All my controllers are extended from Controller.


protected function beforeAction() {

        if (Yii::app()->user->isGuest && !isset(Yii::app()->user->basicType)) {

            Yii::app()->user->setState('basicType', 'anonymous');

            Yii::app()->user->setState('id', $_SERVER['REMOTE_ADDR']);

            //Yii::app()->user->isGuest = true;

        }

        return true;

    }