【发布时间】:2017-06-13 12:29:01
【问题描述】:
我的管理中心页面当前位于 PagesController(称为 admin)中。但是,非登录用户和非管理员用户都可以访问此中心页面,即使他们无法访问该中心的所有链接。
编辑:我刚刚意识到它可能不起作用,因为“admin”不是 PagesController 中的函数,而是属于“display”。
我的AppController如下:
public function initialize()
{
parent::initialize();
$this->loadComponent('RequestHandler');
$this->loadComponent('Flash');
$this->loadComponent('Auth',[
'authorize' => 'Controller',
]);
$this->Auth->allow(['display']);
}
public function beforeFilter(Event $event)
{
$this->Auth->deny(['admin']);
}
我的PagesController如下:
public function initialize()
{
parent::initialize();
$this->Auth->deny(['admin']);
}
public function isAuthorized($user)
{
if (in_array($this->request->action,['admin'])) {
return (bool)($user['role_id'] === 1); //where role_id = 1 refers to an admin
}
return parent::isAuthorized($user);
}
【问题讨论】:
标签: php cakephp authorization cakephp-3.0 cakephp-3.x