Yii rights module redirect to another page if user

2019-09-07 04:11发布

问题:

i install rights module to my site and i create controller called ProfileController

class ProfileController extends RController
{

    public function filters() 
    {
    return array('rights'); 
    } 
}

i decided who can access this controller but when user try to access this page it redirect him to

Error 403
You are not authorized to perform this action.

i need in this case redirect to page PayDetails

i try but fail in this case

回答1:

i found solution to my problem

first: you shold make role to your controller from your rights module like: access profile

second: i create index page any user can access it

public function allowedActions()
    {
    return 'index';
    }

third: i write this code in my index

public function actionIndex()
    {
        $this->layout='column2';
        $lang=Yii::app()->Language;
        $roles=Rights::getAssignedRoles(Yii::app()->user->Id); // check for single role
            foreach($roles as $role)
            if($role->name == 'access profile')
            {
            $this->redirect(array('places'));
            }

        $this->render('index',array('lang'=>$lang));
    }

i think important part in this code

$roles=Rights::getAssignedRoles(Yii::app()->user->Id); // check for single role
foreach($roles as $role)
if($role->name == 'access profile')
{
 $this->redirect(array('places'));
}


标签: php yii