如果用户未经授权,则 Yii 权限模块重定向到另一个页面 403 [英] Yii rights module redirect to another page if user not authorized not 403
问题描述
我在我的网站上安装了权限模块我创建名为 ProfileController
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.
在这种情况下我需要重定向到页面 PayDetails
i need in this case redirect to page PayDetails
我尝试但在这种情况下失败
i try but fail in this case
推荐答案
我找到了解决问题的方法
i found solution to my problem
首先:您从您的权限模块中为您的控制器设置 make 角色如:访问个人资料
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));
}
我认为这段代码很重要
$roles=Rights::getAssignedRoles(Yii::app()->user->Id); // check for single role
foreach($roles as $role)
if($role->name == 'access profile')
{
$this->redirect(array('places'));
}
这篇关于如果用户未经授权,则 Yii 权限模块重定向到另一个页面 403的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!