简体   繁体   中英

How to set different index pages depending on logged in users role in yii

I am working on one yii project. I have used RBAC module in that for user management. My user roles are like Admin , Superadmin , sales , Authenticated , Customer .

I want to redirect users as per their roles after logging in. For example, Admin and Superadmin should see page1 as index page (default action) after they login and customer should see page2 as index page (default action) after they login. I have set the menu depending upon user roles ie which menu tabs should be visible to whom.

Also I am aware about setting default action in yii. ie in main.php file, we have to set default controller action. But I don't understand how can i solve this problem. Please help me for this.

Thanx in advance.

一种可能是仅检查REQUEST_URI是否为/并根据角色重定向到适当的控制器和操作。

I got it working by doing this: In my index action of site controller, I put following logic..

public function actionIndex()
{

    $getroles=Rights::getAssignedRoles(Yii::app()->user->Id);
                    foreach($getroles as $getrole){

                      $getallroles[] = $getrole->name; 
                    }
                    $count_roles = sizeof(array_intersect(array('admin', 'SuperAdmin', 'Sales'), $getallroles));
                    $count_roles1 = sizeof(array_intersect(array('customer'), $getallroles));


    if($count_roles1){
        $this->redirect(array('CategoryImages/showGallery')); 
    }
    else{
        $this->redirect(array('Category/admin')); 

    }
}

Its working as required.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM