How to redirect each type of user to a different page when access is denied?

十年热恋 提交于 2019-12-11 07:37:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!