当访问被拒绝时,如何将每种类型的用户重定向到不同的页面? [英] How to redirect each type of user to a different page when access is denied?

查看:84
本文介绍了当访问被拒绝时,如何将每种类型的用户重定向到不同的页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用中,我具有3个用户角色(用户,管理员,非登录用户),当访问被拒绝时,我想将其重定向到其他页面.该怎么做?

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?

及时,什么$ this-> Auth-> authorize = array('Controller');方法?我在蛋糕文档中不明白这一点.

In time, what $this->Auth->authorize = array('Controller'); means? I didn't understand this in cake docs.

谢谢.

推荐答案

我会在IF语句中使用它,但也许其他人可以建议使用一种更特定于CakePHP的方法..

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');表示授权是在控制器级别完成的.我相信您可以更改使用此授权的位置.

$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.

这篇关于当访问被拒绝时,如何将每种类型的用户重定向到不同的页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆