gpt4 book ai didi

php - 未找到 CakePhp 3 插件身份验证适配器

转载 作者:行者123 更新时间:2023-12-05 05:18:28 24 4
gpt4 key购买 nike

我是 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 类。我已经尝试通过将 authenticate 配置参数设置为

  • 示例
  • 示例验证
  • UserManager.Example
  • Example/UserManager.Example
  • Example\UserManager.Example
  • 示例/UserManager.ExampleAuthenticate
  • Example\UserManager.ExampleAuthenticate

但我总是收到错误 Authentication adapter "..."was not found. 当访问 http://localhost/Project/example/user-manager/users :(

有人知道我可能遗漏了什么吗?

最佳答案

问题是 php函数 class_exists(...)没有识别自定义身份验证类,所以在进一步挖掘之后我意识到文档中显示的命名空间仅适用于应用程序环境中定义的自定义身份验证文件,但不适用于插件环境(愚蠢的我)。

所以我改了namespace App\Auth;namespace Example\UserManager\Auth;里面ExampleAuthenticate.php它就像一个魅力!现在函数 class_exists('Example\\UserManager\\Auth\\ExampleAuthenticate')返回 true通过定义 Example/UserManager.Example 一切都完美无缺在authenticate配置参数。

关于php - 未找到 CakePhp 3 插件身份验证适配器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47898350/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com