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

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办