easy authentication and authorization question


I have a easy question for you.

I am just starting to use the yiiframework and I am currently working on logging, authentication and authorization. My questions are.

Questions one.

Each time I log in I get taken to the home page again, Now do I change this so I get redirected to another paged eg setting.php.

Question two.

If a user is logged in and wants to go to another page within the "loggedin only" pages eg setting_2.php How do i check the users authentication and authorization.

As I said before these are two easy question but all the exmaples I have seen do not seem to explain it clearly.


in your controller, use something like this this


For Question 2. I recommend you to read the rbac section on the Yii Guide

Check the SiteController.php in the default yii webapp. It contains this line, which is executed after successful login:

       	if($model->validate() && $model->login())



This will redirect the user back to the action that required a login. To do so you don’t necessarily need RBAC. You can do like this:

public function actionSomething() {

    if (Yii::app()->user->isGuest)


    // The code hereafter will only execute after login


Thanks sumwai and mike, that works great.