问题
In my app I have 3 roles of Users (user, admin, non logged user), and I want to redirect them to different pages when access is denied. How to do that?
In time, what $this->Auth->authorize = array('Controller'); means? I didn't understand this in cake docs.
Thanks all.
回答1:
I would have it in a IF statement, but perhaps someone else can suggest a more CakePHP specific method..
if($user === 'Admin') {
//Admin Redirect
$redirectController = 'admin';
$redirectMethod = 'admin_index';
} elseif ($user === 'User') {
//User Redirect
$redirectController = 'user';
$redirectMethod = 'index';
} else {
//Not logged in
$redirectController = 'SomeController';
$redirectMethod = 'someMethod';
}
$this->Auth->unauthorizedRedirect = array(
'controller' => $redirectController,
'action' => $redirectMethod
);
$this->Auth->authorize = array('Controller');
means that the Authorization is done at the Controller level. I believe you can change where authorization is carried out using this.
来源:https://stackoverflow.com/questions/24059455/how-to-redirect-each-type-of-user-to-a-different-page-when-access-is-denied