yii : how to redirect to different page after logged in?

Q : how to redirect to different page after logged in?

status : I've custom user role and I want to redirect to different page for different user.

e.g hr manager -> employee/index, account manager -> account/index.

I'm using yii 1.1.xx and rights module. yii and rights module are going with green.

update question's info

this is the rank tbl

this is user tbl

If the rank is Account Manager, the web site will redirect to account/index.

If the rank is HR manager, the web site will redirect to employee/index.


} else if(Yii::app()->user->checkAccess('accountManager',Yii::app()->user->getId())==1) {

Where hrManager and accountManager are the corresponding access rules for the HR Manager and Account Manager logins. This will check to see if the user has 'HR Manager' level access, if so redirect them there, and then checks if the user has 'Account Manager' level access, if so redirects them to that page.

Obviously you can customise to how it suits your app, as the above code won't redirect anywhere if the user has neither HR Manager or Account Manager access, so you'll need another catcher.


The hrManager string is the rbac authitem name, do you have tables authassignment authitem and authitemchild set up for your rbac?

If not, you can use this method a little differently using your ranking table. you can either set it up using the rank_id, but you'd have to load the user model (if you haven't already got it loaded) which might not be the most efficient way of doing it.

$user = User::model()->findbyPk(Yii::app()->user->getId());
} else if($user->rank_id==2)) {

The other way would be to load the users rank into the Yii::app()->user param after login so you don't have to load the user model before the redirect, maybe you have this set up already for however you are granting access to pages?

} else if(Yii::app()->user->rank_id==2)) {

Something like $this->redirect(array("controller/admin")); ?

Need Your Help

Tips, Tricks, Shortcuts for using EnigmaCurry's Emacs configuration

python emacs emacs23

I just stated using emacs and wanted to find a good configuration for python programming.

FOSUserBundle - add login extra field

symfony fosuserbundle symfony-2.7

I have a registration form with extra field. Below is my code: