如何去掉cakephp认证中的"redirect"参数?

How to remove the "redirect" parameter in cakephp authentication?

我希望用户在没有登录的情况下被重定向到登录页面,但是 URL.

中没有 "redirect" 参数 这是我的代码:

<code>
    $this->loadComponent('Auth', [
        'authenticate' => [
            'Form' => [
                'fields' => [
                    'username' => 'email',
                    'password' => 'password'
                ]
            ],
        ],
        'loginAction' => [
            'controller' => 'Auth',
            'action' => 'login'
        ],
    ]);
</code>

我希望输出是 admin/auth/login,但实际输出是admin/auth/login?redirect=%2Fadmin%2F

我已经查看了文档,但一无所获。

我通过重写 AuthComponent class (Cake\Controller\Component\AuthComponent) 解决了这个问题。为此,我按照文档为组件创建了一个别名 (https://book.cakephp.org/3.0/en/controllers/components.html#aliasing-components)

我重写了 _loginActionRedirectUrl() 函数,使其成为 return $this->_config['loginAction'];

您需要将参数 'unauthorizedRedirect' => false 添加到您的代码中。所以你的代码看起来像

$this->loadComponent('Auth', [
    'authenticate' => [
        'Form' => [
            'fields' => [`enter code here`
                'username' => 'email',
                'password' => 'password'
            ]
        ],`enter code here`
    ],
    'loginAction' => [
        'controller' => 'Auth',
        'action' => 'login'
    ],
    'unauthorizedRedirect' => false
]);

希望对您有所帮助。
有关更多信息,您可以查看 Here