找不到CakePhp 3插件身份验证适配器

沃伦

我是Cakephp(3.5)的新手,目前正在尝试制作第一个Example包含几个子目录的插件(称为)。其中之一是UserManager目录,其中包含带有身份验证的Users MVC标准套件。

由于我想添加社交登录名和其他内容,因此我创建了自己的auth组件,如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配置参数来尝试

  • Example
  • ExampleAuthenticate
  • UserManager.Example
  • Example/UserManager.Example
  • Example\UserManager.Example
  • Example/UserManager.ExampleAuthenticate
  • Example\UserManager.ExampleAuthenticate

但是Authentication adapter "..." was not found.访问http://localhost/Project/example/user-manager/users:(

有人对我可能缺少的东西有任何线索吗?

沃伦

问题在于该php函数class_exists(...)无法识别自定义身份验证类,因此在进行了更多研究后,我意识到文档中显示的名称空间仅适用于在App环境中定义的自定义身份验证文件,而不适用于插件环境(傻我)。

所以我换namespace App\Auth;namespace Example\UserManager\Auth;里面ExampleAuthenticate.php,它就像一个魅力!现在该函数class_exists('Example\\UserManager\\Auth\\ExampleAuthenticate')返回,true并且通过Example/UserManager.Exampleauthenticateconfig参数中定义一切都可以完美运行

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章