我已经按照教程和所有CakePHP授权指南,我无法调用我的isAuthorized()方法.我的理解(纠正我,如果我错了,这是令人难以置信的可能)是通过委派做授权给特定的控制器'authorize'->['Controller']中AppController.php,当UsersController的方法被调用,在这种情况下,"添加",UsersController将运行isAuthorized()我定义的方法.我正在测试看看这个方法是否在isAuthorized()调用时输出flash->错误消息,但没有任何反应.如果我明确地调用isAuthorized($hardcodeduser)我的beforeFilter()方法它将工作,但只有我硬编码用户.
该方法应该起作用的方式是:如果注册用户请求添加/创建新用户,系统将检查用户是否具有管理员/员工级权限(在数据库中只是0或1值)如果用户没有权限,则会重定向到主屏幕,并显示"您无权访问该功能"的错误消息.
任何帮助或建议或其他链接将非常感谢!
class AppController extends Controller {
public $components = ['Flash', 'Auth', 'Session'];
public function initialize() {
$this->loadComponent('Flash');
$this->loadComponent('Auth', [
'authorize' => ['Controller'],
'loginRedirect' => [
'controller' => 'Articles',
'action' => 'index'
],
'logoutRedirect' => [
'controller' => 'Pages',
'action' => 'display',
'home'
]
]);
}
public function beforeFilter(Event $event) {
$this->Auth->authorize = 'Controller';
}
public function isAuthorized($user) {
if(isset($user['is_staff']))
return true;
return false;
}
}
class …Run Code Online (Sandbox Code Playgroud)