CakeDC 用户似乎无法加载自定义控制器

CakeDC Users appears to be unable to load custom Controller

我有一个 CakePHP 应用程序 运行ning on Cake PHP 3.8.13,CakeDC Users 8.5.1 和 PHP 7.4。我正在尝试使用自定义控制器,以便我可以调整 LoginTrait 和 PasswordChangeTrait 的行为。

我一直在关注 https://github.com/CakeDC/users/blob/master/Docs/Documentation/Configuration.md#using-the-users-email-to-login

中的文档

但是我的自定义 UsersController 没有被使用。

我已将以下行添加到 /config/bootstrap。php

Configure::write('Users.config', ['users']);
Plugin::load('CakeDC/Users', ['routes' => true, 'bootstrap' => true]);

我创建了一个新文件/config/users.php

<?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',
            'controller' => 'Users',
            'action' => 'verify',
            'prefix' => false,
        ],
    ],
    'U2f' => [
        'enabled' => false,
        'checker' => \CakeDC\Users\Auth\DefaultU2fAuthenticationChecker::class,
        'startAction' => [
            'plugin' => 'CakeDC/Users',
            'controller' => 'Users',
            'action' => 'u2f',
            'prefix' => false,
        ]
    ],
    
];

return $config;

请注意,指定的 table 名称不是真正的 class 名称并且不存在。该应用程序继续 运行 没有问题。如果我将配置更改为:

$config = [
    'Users' => [
        // Table used to manage users
        'table' => '\SomethingThatDoesNotExist',
...

即只需将反斜杠添加到 table 名称 我收到错误消息

Class '\SomethingThatDoesNotExist' not found. Error in: ROOT\vendor\cakephp\cakephp\src\ORM\Locator\TableLocator.php, line 239

我实际上不需要自定义 table 我想自定义控制器,但无论我在控制器配置中输入什么,我都没有收到错误!我在以下路径 /src/Controller/MyUsersController.php 中有一个有效的控制器,但是以下配置的 none 触发了它的使用:

'controller' => 'MyUsers',
'controller' => '\MyUsers',
'controller' => 'App\Controller\MyUsers',
'controller' => '\App\Controller\MyUsers',

如何加载我的自定义控制器?

似乎自定义控制器不会覆盖当前路由,它只会根据自定义控制器名称覆盖,即 /myusers/login

而不是 /login