使用此参考获得解决方案
我将 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';
}
这解决了我的问题:)