得到使用該溶液
此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