Cakephp 如何使用UnauthorizedDirect将不同角色的用户重定向到各自的页面?
在我的应用程序中,我有一个拥有3个不同角色的用户,每个角色都有自己的页面,可以访问。当他们试图访问任何不应该查看但无法访问的页面时,我想将他们重定向到各自的主页 我发现下面的线程有一个非常类似的问题,但是在修改代码并将其放入AppController::beforefilter之后,我无法获得所需的结果 使用上面线程中的代码更新:Cakephp 如何使用UnauthorizedDirect将不同角色的用户重定向到各自的页面?,cakephp,cakephp-3.0,Cakephp,Cakephp 3.0,在我的应用程序中,我有一个拥有3个不同角色的用户,每个角色都有自己的页面,可以访问。当他们试图访问任何不应该查看但无法访问的页面时,我想将他们重定向到各自的主页 我发现下面的线程有一个非常类似的问题,但是在修改代码并将其放入AppController::beforefilter之后,我无法获得所需的结果 使用上面线程中的代码更新: public function beforeFilter(Event $event) { $user_role = $this->Auth->u
public function beforeFilter(Event $event)
{
$user_role = $this->Auth->user('role');
if ($user_role == "admin")
{
$redirectController = 'Pages';
$redirectMethod = 'adminhome';
}
elseif ($user_role == "teacher")
{
$redirectController = 'Pages';
$redirectMethod = 'teacherhome';
}
elseif ($user_role == "studentparent")
{
$redirectController = 'Pages';
$redirectMethod = 'parenthome';
}
$this->Auth->unauthorizedRedirect = array(
'controller' => $redirectController,
'action' => $redirectMethod,
'prefix' => false
);
}
请务必在这里发布您的代码。嗨,版本是3.4.5。我已经用代码更新了线程,谢谢你得到了什么结果?