我将权限模块安装到我的站点我创建了一个名为ProfileController
的控制器
class ProfileController extends RController
{
public function filters()
{
return array('rights');
}
}
我决定谁可以访问这个控制器,但当用户试图访问这个页面时,它会将他重定向到
Error 403
You are not authorized to perform this action.
在这种情况下,我需要重定向到页面PayDetails
我尝试过,但在这种情况下失败了
我找到了问题的解决方案
第一:您可以从权限模块中为控制器创建角色类似:访问配置文件
第二:我创建索引页面任何用户都可以访问它
public function allowedActions()
{
return '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));
}
我认为这个代码中的重要部分
$roles=Rights::getAssignedRoles(Yii::app()->user->Id); // check for single role
foreach($roles as $role)
if($role->name == 'access profile')
{
$this->redirect(array('places'));
}