未找到 CakePhp 3 插件身份验证适配器
CakePhp 3 Plugin Authentication adapter was not found
我有点像 Cakephp (3.5) 的新手,我目前正在尝试制作我的第一个插件(称为 Example
),其中包含几个子目录。其中之一是 UserManager
目录,其中包含带有身份验证的 Users MVC 标准套装。
因为我想添加社交登录和其他内容,所以我创建了自己的身份验证组件,如 docs 中所述:
plugins/Example/UserManager/src/Controller/AppController.php
<?php
namespace Example\UserManager\Controller;
use App\Controller\AppController as BaseController;
class AppController extends BaseController
{
public function initialize()
{
parent::initialize();
$this->loadComponent('Auth', [
'authenticate' => [
'Example/UserManager.Example' => [
'fields' => ['username' => 'email', 'password' => 'pass'],
'userModel' => 'Users',
],
],
]);
}
}
plugins/Example/UserManager/src/Auth/ExampleAuthenticate.php
<?php
namespace App\Auth;
use Cake\Auth\BaseAuthenticate;
use Cake\Http\ServerRequest;
use Cake\Http\Response;
class ExampleAuthenticate extends BaseAuthenticate
{
// The same as Form authentication, since I'm testing
}
问题是我无法让身份验证组件找到 ExampleAuthenticate
class。我已经尝试将 authenticate
配置参数设置为
Example
ExampleAuthenticate
UserManager.Example
Example/UserManager.Example
Example\UserManager.Example
Example/UserManager.ExampleAuthenticate
Example\UserManager.ExampleAuthenticate
但我在访问 http://localhost/Project/example/user-manager/users
时总是收到错误 Authentication adapter "..." was not found.
:(
有人知道我可能遗漏了什么吗?
问题是 php
函数 class_exists(...)
无法识别自定义身份验证 class,所以在进一步挖掘之后我意识到文档中显示的命名空间只适用于在 App 环境中定义的自定义身份验证文件,但不适用于插件环境(愚蠢的我)。
所以我在 ExampleAuthenticate.php
中将 namespace App\Auth;
更改为 namespace Example\UserManager\Auth;
,效果非常好!现在函数 class_exists('Example\UserManager\Auth\ExampleAuthenticate')
returns true
并且通过在 authenticate
配置参数中定义 Example/UserManager.Example
一切都完美无缺。
我有点像 Cakephp (3.5) 的新手,我目前正在尝试制作我的第一个插件(称为 Example
),其中包含几个子目录。其中之一是 UserManager
目录,其中包含带有身份验证的 Users MVC 标准套装。
因为我想添加社交登录和其他内容,所以我创建了自己的身份验证组件,如 docs 中所述:
plugins/Example/UserManager/src/Controller/AppController.php
<?php
namespace Example\UserManager\Controller;
use App\Controller\AppController as BaseController;
class AppController extends BaseController
{
public function initialize()
{
parent::initialize();
$this->loadComponent('Auth', [
'authenticate' => [
'Example/UserManager.Example' => [
'fields' => ['username' => 'email', 'password' => 'pass'],
'userModel' => 'Users',
],
],
]);
}
}
plugins/Example/UserManager/src/Auth/ExampleAuthenticate.php
<?php
namespace App\Auth;
use Cake\Auth\BaseAuthenticate;
use Cake\Http\ServerRequest;
use Cake\Http\Response;
class ExampleAuthenticate extends BaseAuthenticate
{
// The same as Form authentication, since I'm testing
}
问题是我无法让身份验证组件找到 ExampleAuthenticate
class。我已经尝试将 authenticate
配置参数设置为
Example
ExampleAuthenticate
UserManager.Example
Example/UserManager.Example
Example\UserManager.Example
Example/UserManager.ExampleAuthenticate
Example\UserManager.ExampleAuthenticate
但我在访问 http://localhost/Project/example/user-manager/users
时总是收到错误 Authentication adapter "..." was not found.
:(
有人知道我可能遗漏了什么吗?
问题是 php
函数 class_exists(...)
无法识别自定义身份验证 class,所以在进一步挖掘之后我意识到文档中显示的命名空间只适用于在 App 环境中定义的自定义身份验证文件,但不适用于插件环境(愚蠢的我)。
所以我在 ExampleAuthenticate.php
中将 namespace App\Auth;
更改为 namespace Example\UserManager\Auth;
,效果非常好!现在函数 class_exists('Example\UserManager\Auth\ExampleAuthenticate')
returns true
并且通过在 authenticate
配置参数中定义 Example/UserManager.Example
一切都完美无缺。