Cakephp身份验证重定向

Cakephp身份验证重定向,php,cakephp,redirect,Php,Cakephp,Redirect,我刚开始尝试学习cakephp auth,我只是复制并粘贴代码,试图理解它。我不知道什么是直接重定向 //应用程序控制器 //是空的我知道在某些情况下你把它放在这里,我只是在用户控制器中测试它 public $components = array('Paginator', 'Session', 'Auth' => array( 'loginAction' => array( 'controller' => 'users',

我刚开始尝试学习cakephp auth,我只是复制并粘贴代码,试图理解它。我不知道什么是直接重定向

//应用程序控制器 //是空的我知道在某些情况下你把它放在这里,我只是在用户控制器中测试它

public $components = array('Paginator',
 'Session', 
 'Auth' => array(
        'loginAction' => array(
            'controller' => 'users',
            'action' => 'login',
            'plugin' => 'users'
        ),
        'authError' => 'Did you really think you are allowed to see that?',
        'authenticate' => array(
            'Form' => array(
                'fields' => array('username' => 'email')
            )
        )
    )

);


 public function beforeFilter() {
       $this->Auth->allow('index', 'view');
}

public function login() {
    if ($this->request->is('post')) {
        if ($this->Auth->login()) {
            return $this->redirect($this->Auth->redirectUrl());
            // Prior to 2.3 use
            // `return $this->redirect($this->Auth->redirect());`
        } else {
            $this->Session->setFlash(
                __('Username or password is incorrect'),
                'default',
                array(),
                'auth'
            );
        }
    }
}
//用户控制器

public $components = array('Paginator',
 'Session', 
 'Auth' => array(
        'loginAction' => array(
            'controller' => 'users',
            'action' => 'login',
            'plugin' => 'users'
        ),
        'authError' => 'Did you really think you are allowed to see that?',
        'authenticate' => array(
            'Form' => array(
                'fields' => array('username' => 'email')
            )
        )
    )

);


 public function beforeFilter() {
       $this->Auth->allow('index', 'view');
}

public function login() {
    if ($this->request->is('post')) {
        if ($this->Auth->login()) {
            return $this->redirect($this->Auth->redirectUrl());
            // Prior to 2.3 use
            // `return $this->redirect($this->Auth->redirect());`
        } else {
            $this->Session->setFlash(
                __('Username or password is incorrect'),
                'default',
                array(),
                'auth'
            );
        }
    }
}
我理解before过滤器有意义,它只允许索引和查看,我有另一个名为admin的控制器,如果您未登录,它会重定向到登录页面


但出于某种原因,它一直重定向到users/users/login,我想让它转到users/login?如何修复此问题?

您只需将控制器放在任何地方,然后执行操作即可

  public function login() {  
            if ($this->request->is('post')) {
                if ($this->Auth->login()) { 
                  return $this->redirect(array('controller' => 'users', 'action' => 'login'));
                }
            } else {
                    $this->Session->setFlash(__('Invalido nombre de usuario o contraseña'));
            }
     } 

你试过对
'plugin'=>'users'
部分进行注释吗?请参阅我的答案