1
我正在使用cakePHP的isAuthorized()函數來檢查用戶是否被授權執行控制器操作,但是我遇到的奇怪問題是我的其他控制器操作的權限被阻止來自用戶。我只是這樣做:奇怪的cakePHP isAuthorized()問題
function isAuthorized()
{
$user_id_logged_in = $this->Auth->user('id');
switch($this->action)
{
case: 'my_action':
if($user_id_logged_in)
{
// check if user has access to execute controller action
return $this->Acl->check(array(
'model' => 'MyModel', 'foreign_key' => $my_foreign_key),
'controllers/MyController/'.$this->action);
}
else
{
return false;
}
break;
}
}
我要檢查,如果登錄用戶被授權執行的動作my_action
。但是當我這樣做時,用戶也失去了我控制器中其他操作的權限。任何想法這有什麼問題?
謝謝
你在哪裏設置'$ user_id_logged_in'? – 2012-03-01 23:25:36
$ user_id_logged_in就等於'$ this-> Auth-> user('id');' – user765368 2012-03-01 23:26:50
從我可以從文檔中得知,'check()'方法需要3個字符串參數。 '檢查($ aro,$ aco,$ action =「*」)'。你可以看到[這裏](http://api20.cakephp.org/class/acl-component#method-AclComponentcheck)。 – 2012-03-01 23:36:19