1

谁能解释我Auth->authorize = "actions"
在我的项目中的工作,我正计划给这个。
正如告诉我的那样,授权将调用$this->Aro->check($user,"controllers/:controller/:action")

这将检查对用户的权利?
这意味着用户应该在 aros 表中。
但我不需要这个来检查用户,但我需要检查一个组
我怎样才能做到这一点。

现在当用户不在 Aro 表中时,它会显示

这样 Aro 将只是组,并且需要将用户添加到 Aros

提前谢谢

4

2 回答 2

1


使用此参考获得解决方案
我将 AuthComponent 扩展到 CustomAuth 并覆盖isAutorized()AuthComponent 中的方法,如下所示

在控制器/组件/custom_auth.php

    <?php
App::import('Component','Auth');
class CustomAuthComponent extends AuthComponent {

    public function isAuthorized($type = null, $object = null, $user = null) {

        $actions  = $this->__authType($type);
        if( $actions['type'] != 'actions' ){
            return parent::isAuthorized($type, $object, $user);
        }
        if (empty($user) && !$this->user()) {
            return false;
        } elseif (empty($user)) {
            $user = $this->user();
        }


        $group = array('model' => 'Group','foreign_key' =>$user['Login']['group_id']);
        $valid = $this->Acl->check($group, $this->action());
        return $valid;
    }
}
?>

在 app_controller.php

function beforeFilter()
{
$this->CustomAuth->userModel = 'Login';
$this->CustomAuth->allowedActions = array('display');
$this->CustomAuth->actionPath = 'controllers/';
$this->CustomAuth->authorize = 'actions';
}

这解决了我的问题:)

于 2010-08-07T12:31:46.910 回答
0

看看这一。要检查组权限,请执行此操作('model' 和 'foreign_key' 值来自 aros 表):

$this->Acl->check(
     array('model' => 'Group', 'foreign_key' => 2),
    'controller/action'
);
于 2010-08-05T17:06:48.150 回答