问题描述
我有一个在Cake PHP 3.8.13,CakeDC Users 8.5.1和PHP 7.4上运行的CakePHP应用程序。我试图使用自定义控制器,以便可以调整LoginTrait和PasswordChangeTrait的行为。
中的文档但是未使用我的自定义UsersController。
我已将以下行添加到 /config/bootstrap.PHP
description
summary
请注意,指定的表名不是真实的类名,并且不存在。该应用程序继续运行,没有任何问题。如果我将配置更改为:
Configure::write('Users.config',['users']);
Plugin::load('CakeDC/Users',['routes' => true,'bootstrap' => true]);
<?PHP
$config = [
'Users' => [
// Table used to manage users
'table' => 'SomethingThatDoesNotExist',// Controller used to manage users plugin features & actions
'controller' => 'MyUsers',// configure Auth component
'auth' => true,// Password Hasher
'passwordHasher' => '\Cake\Auth\DefaultPasswordHasher',// token expiration,1 hour
'Token' => ['expiration' => 3600],'Email' => [
// determines if the user should include email
'required' => true,// determines if registration workflow includes email validation
'validate' => true,],'Registration' => [
// determines if the register is enabled
'active' => false,// determines if the reCaptcha is enabled for registration
'reCaptcha' => true,// allow a logged in user to access the registration form
'allowLoggedIn' => false,//ensure user is active (confirmed email) to reset his password
'ensureActive' => false,// default role name used in registration
'defaultRole' => 'user','reCaptcha' => [
// reCaptcha key goes here
'key' => null,// reCaptcha secret
'secret' => null,// use reCaptcha in registration
'registration' => false,// use reCaptcha in login,valid values are false,true
'login' => false,'Tos' => [
// determines if the user should include tos accepted
'required' => true,'Social' => [
// enable social login
'login' => false,// enable social login
'authenticator' => 'CakeDC/Users.social','GoogleAuthenticator' => [
// enable Google Authenticator
'login' => false,'issuer' => null,// The number of digits the resulting codes will be
'digits' => 6,// The number of seconds a code will be valid
'period' => 30,// The algorithm used
'algorithm' => 'sha1',// QR-code provider (more on this later)
'qrcodeprovider' => null,// Random Number Generator provider (more on this later)
'rngprovider' => null
],'Profile' => [
// Allow view other users profiles
'viewOthers' => true,'route' => ['prefix' => false,'plugin' => 'CakeDC/Users','controller' => 'Users','action' => 'profile'],'Key' => [
'Session' => [
// session key to store the social auth data
'social' => 'Users.social',// userId key used in reset password workflow
'resetPasswordUserId' => 'Users.resetPasswordUserId',// form key to store the social auth data
'Form' => [
'social' => 'social'
],'Data' => [
// data key to store the users email
'email' => 'email',// data key to store email coming from social networks
'socialEmail' => 'info.email',// data key to check if the remember me option is enabled
'rememberMe' => 'remember_me',// Avatar placeholder
'Avatar' => ['placeholder' => 'CakeDC/Users.avatar_placeholder.png'],'RememberMe' => [
// configure Remember Me component
'active' => false,'checked' => true,'Cookie' => [
'name' => 'remember_me','Config' => [
'expires' => '1 month','httpOnly' => true,]
]
],'Superuser' => ['allowedtochangePasswords' => true],'GoogleAuthenticator' => [
'checker' => \CakeDC\Users\Auth\DefaultTwoFactorAuthenticationChecker::class,'verifyAction' => [
'plugin' => 'CakeDC/Users','action' => 'verify','prefix' => false,'U2f' => [
'enabled' => false,'checker' => \CakeDC\Users\Auth\DefaultU2fAuthenticationChecker::class,'startAction' => [
'plugin' => 'CakeDC/Users','action' => 'u2f',]
],];
return $config;
我实际上不需要自定义要自定义控制器的表,但是无论我在控制器配置中输入什么,都不会收到错误!我在以下路径 /src/Controller/MyUsersController.PHP 中有一个有效的控制器,但是以下任何配置均不会触发其使用:
$config = [
'Users' => [
// Table used to manage users
'table' => '\SomethingThatDoesNotExist',...
如何加载我的自定义控制器?
解决方法
看来,自定义控制器不会覆盖它的当前路由,而只会基于自定义控制器名称覆盖它,即,不是/ login而是/ myusers / login