dongling3243 2014-09-17 15:45
浏览 59
已采纳

如果用户未被授权,则Yii权限模块重定向到另一页面403

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条回答 默认 最新

  • dongque5529 2014-09-17 17:11
    关注

    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'));
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)