且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Cakephp 3身份验证插件,登录URL不匹配

更新时间:2023-12-02 09:29:04

错误消息目前有点误导,因为它没有向您显示可能的基本目录,这是您遇到的实际问题.我已经提出了 对此问题的修复 进入下一个版本.

The error messages is currently a little misleading, as it doesn't show you the possible base directory, which is the actual issue that you are experiencing. I've proposed a fix for that, which may make into the next release.

当您的应用程序位于子目录中时,您需要确保将登录URL配置考虑在内,即通过传递包含基本目录的URL,您可以手动执行以下操作:

When your application lives in a subdirectory, you need to make sure that your login URL configuration takes that into account, that is by either passing the URL including the base directory, which you could do either manually:

'loginUrl' => '/myapp/users/login'

或使用路由器:

'loginUrl' => \Cake\Routing\Router::url('/users/login')

'loginUrl' => \Cake\Routing\Router::url([
    'plugin' => null,
    'prefix' => null,
    'controller' => 'Users',
    'action' => 'login'
])

另一种选择是使用基于路由的URL检查器,该检查器可以通过表单身份验证器urlChecker选项进行配置,然后您可以使用URL数组定义登录URL,而不必使用路由器:

Another option would be to use the routes based URL checker, which can be configured via the form authenticators urlChecker option, then you can define the login URL using URL arrays, without having to use the router:

'urlChecker' => 'Authentication.CakeRouter',
'loginUrl' => [
    'plugin' => null,
    'prefix' => null,
    'controller' => 'Users',
    'action' => 'login'
]

另请参阅: