【问题标题】:Why the accessRules doesen't work in my yii module, the yii version is 1.1为什么 accessRules 在我的 yii 模块中不起作用,yii 版本是 1.1
【发布时间】:2018-12-16 07:36:17
【问题描述】:

我想让经过身份验证的用户可以访问我的

admin(module)/sysMessage(controller)/index(action)

我的访问规则如下:

public function accessRules()
    {
        return array(
            array('allow',  // allow only users in the 'admin' role access to our actions
                'actions'=>array('index','view', 'create', 'update', 'admin', 'delete'),
                'roles'=>array('admin'),
            ),
                array('allow',  
                        'actions'=>array('index','view'),
                        'roles'=>array('@'),
                ),
            array('deny',  // deny all users
                'users'=>array('*'),
            ),
        );
    }

但是,当经过身份验证的用户试图访问我的

admin(module)/sysMessage(controller)/index(action),他们收到了这条消息:

“错误 403 您无权执行此操作。”

你能告诉我为什么吗?

【问题讨论】:

    标签: php yii


    【解决方案1】:

    当我们使用模块/控制器/动作时,我们应该检查

    /yiiroot/trackstar/protected/modules/admin/yourModule.php

    我将“public function beforeControllerAction”改成如下,问题就解决了。

    参考:Create AccessRules in modules Yii Framework

    public function beforeControllerAction($controller, $action)
         {
          if(parent::beforeControllerAction($controller, $action))
         {
          // this method is called before any module controller action is performed
           // you may place customized code here
    
         if(Yii::app()->user->isGuest){
         $url = Yii::app()->createUrl(Yii::app()->user->loginUrl);
         Yii::app()->user->returnUrl = Yii::app()->createUrl('/admin/');
         Yii::app()->request->redirect($url);
        }
         else {
           return true;
         }
    
    
         }
         else
         return false;
         }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-21
      相关资源
      最近更新 更多