Authentication CakePHP登录重定向管理员/用户

Authentication CakePHP登录重定向管理员/用户,authentication,cakephp,login,Authentication,Cakephp,Login,我使用的登录功能如下 public function login() { if ($this->request->is('post')) { $user = $this->Auth->identify(); if ($user) { if ($user['warning'] == false) { $this->Auth->setUser($user);

我使用的登录功能如下

public function login()
{

    if ($this->request->is('post')) {
        $user = $this->Auth->identify();
        if ($user) {
            if ($user['warning'] == false) {
                $this->Auth->setUser($user);
                if ($this->Auth->user('role') == 'admin') {
                    if(isset($this->Auth->redirectUrl)){
                        return $this->redirect($this->Auth->redirectUrl());
                    }
                    else return $this->redirect(['controller' => 'adresses','action' => 'adminindex']);


                } elseif ($this->Auth->user('role') == 'user') {
                    if(isset($this->Auth->redirectUrl)){
                        return $this->redirect($this->Auth->redirectUrl());
                    }
                    else return $this->redirect(['controller' => 'adresses','action' => 'index']);
                }
            }
            else{
                $this->Flash->error(__('XXXX'));
                return $this->redirect(['action' => 'login']);
            }
        }
        $this->Flash->error(__('XXXXX'));
    }
}
我现在的问题是,我似乎无法读取重定向URL,因为每次我来自需要登录用户的链接时,我都会被转发到AppController中定义的地址索引。但我需要它重定向到adminindex


我可以切换管理员和用户的回退吗。或者有人知道如何检查重定向URL是否设置了吗?

redirectUrl
AuthComponent
中的一个函数,而不是一个变量,因此我认为您需要在
isset
检查中添加括号

if (isset($this->Auth->redirectUrl())) 

redirectUrl
AuthComponent
中的一个函数,不是一个变量,因此我认为需要在
isset
检查中添加括号

if (isset($this->Auth->redirectUrl()))