我想使用isAuthorized()方法來檢查管理標誌,但函數似乎永遠不會被調用。即使我將函數設置爲始終返回false,它也允許任何用戶。它看起來好像沒有被調用。cakephp isAuthorized()沒有被調用
我需要做更多的事情嗎?設置$ this-> Auth-> authorize ='controller'?
從/app/app_controller.php
class AppController extends Controller
{
var $components = array('Auth');
function beforeFilter()
{
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
$this->Auth->loginRedirect = array('controller' => 'pages', 'display' => 'home');
$this->Auth->logoutRedirect = '/';
$this->Auth->authorize = 'controller';
$this->Auth->userScope = array('User.active' => 1);
}
function isAuthorized()
{
if (strpos($this->action, "admin_") != false)
{
if ($this->Auth->user('isAdmin') == '0')
{
return false;
}
}
return true;
}
}
事實證明我重寫beforeFilter()而不是調用parent :: beforeFilter() – 2009-04-22 01:50:36