doucheng2053 2012-11-05 21:19
浏览 90
已采纳

Yii simple rbac - checkAccess未执行

I'm new to Yii. I used this tutorial: http://www.yiiframework.com/wiki/328/simple-rbac/ to make admin role working. My accessRules function in controller looks like this:

 public function accessRules() {
        return array(
            array('allow', // allow all users to perform 'index' and 'view' actions
                'actions' => array('index', 'view', 'create'),
                'users' => array('*'),
            ),
            array('allow', // allow authenticated user to perform 'create' and 'update' actions
                'actions' => array('update'),
                'users' => array('@'),
            ),
            array('allow', // allow admin user to perform 'admin' and 'delete' actions
                'actions' => array('delete', 'admin'),
                'users' => array('admin'),
            ),
            array('deny', // deny all users
                'users' => array('*'),
            ),
        );
    }

If I understood - it should execute checkAccess function from WebUser class when I try to view admin or delete action. My checkAccess function looks like this:

public function checkAccess($operation,$params=array(),$allowCaching=true) {
    die("it works!");
    if (empty($this->id)) {
        // Not identified => no rights
        return false;
    }
    $admin = $this->getState("admin");

    return ($operation === 'admin' && $admin == ROLE_ADMIN || $operation !== 'admin');
}

So it should view "it works!" but I get

Error 403

You are not authorized to perform this action.

What did I do wrong?

  • 写回答

1条回答 默认 最新

  • douxiong1994 2012-12-20 22:23
    关注
    Try changing 'users'=>array('admin') to 'roles'=>array('admin')
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!