得到使用该溶液
此reference
我延长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-07 12:31:46
RSK
但由于Auth->授权=“行动”中给出的检查将完成全自动吧? – RSK 2010-08-05 18:44:08
没错。您需要使用'$ this-> Auth-> authorize ='controller';'和'isAuthorized()'方法(http://book.cakephp.org/view/396/authorize)。 – bancer 2010-08-05 23:13:17
,但是如果我给'$ this-> Auth-> authorize ='controller';'我需要转到每个控制器并重写'isAuthorized()'。我怎样才能避免在每个控制器这个重写? – RSK 2010-08-07 05:22:21