CakePHP 4 CMS身份验证教程重定向到登录无效(忽略子文件夹) [英] CakePHP 4 CMS Authentication Tutorial redirection to login not working (subfolder ignored)

查看:164
本文介绍了CakePHP 4 CMS身份验证教程重定向到登录无效(忽略子文件夹)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据官方CMS教程实施身份验证: https://book.cakephp.org/4/en/tutorials-and-examples/cms/authentication.html#adding-login

Im trying to implement an authentication according to the offical CMS Tutorial: https://book.cakephp.org/4/en/tutorials-and-examples/cms/authentication.html#adding-login

但是重定向在这里实现:

But the Redirection implemented here:

public function getAuthenticationService(ServerRequestInterface $request): AuthenticationServiceInterface
{
    $authenticationService = new AuthenticationService([
        'unauthenticatedRedirect' => '/users/login',
        'queryParam' => 'redirect',
    ]); 

无法按预期工作。

我的安装位于example.com/project1/之类的子文件夹中,正确的完整URL为example.com/project1/users/login,但是当尝试访问example.com/project1/时,重定向指向example.com/users/登录。

My Installation is in a subfolder like example.com/project1/ and the correct full url would be example.com/project1/users/login but when trying to reach example.com/project1/ the redirection points to example.com/users/login.

我也尝试更改

$authenticationService = new AuthenticationService([
        'unauthenticatedRedirect' => '/users/login',
        'queryParam' => 'redirect',

$authenticationService = new AuthenticationService([
        'unauthenticatedRedirect' => [controller => 'users', 'action' => index],
        'queryParam' => 'redirect',

但这会导致


parse_url()期望参数1为字符串,给出的数组

parse_url() expects parameter 1 to be string, array given

错误

如何设置重定向或在CakePHP 4中可以在哪里更改 BASEURL?

How do I have to set the redirection or where can I change the "BASEURL" in CakePHP 4?

推荐答案

问题。

我已根据@ndm的链接更改了代码

I changed the code according to @ndm's link to this:

$authenticationService = new AuthenticationService([
        'unauthenticatedRedirect' => \Cake\Routing\Router::url('/users/login'),
        'queryParam' => 'redirect',

导致无限重定向,因为我忘了将此函数添加到UsersController :

leading to an infinite redirect, because I had forgotten to add this function to the UsersController:

public function beforeFilter(\Cake\Event\EventInterface $event)
{
    parent::beforeFilter($event);
    // Configure the login action to not require authentication, preventing
    // the infinite redirect loop issue
    $this->Authentication->addUnauthenticatedActions(['login']);
}

这篇关于CakePHP 4 CMS身份验证教程重定向到登录无效(忽略子文件夹)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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