即使插件的类在composer.json中正确配置:
"autoload": {
"psr-4": {
"App\\": "src",
"Blog\\": "./plugins/Blog/src",
"Media\\": "./plugins/Media/src",
"Cms\\": "./plugins/Cms/src",
"Feedback\\": "./plugins/Feedback/src"
}
},
和插件在bootstrap.php中加载:
Plugin::load('Blog', ['routes' => true, 'autoload' => true]);
Plugin::load('Cms', ['routes' => true, 'autoload' => true]);
Plugin::load('Media', ['routes' => true, 'autoload' => true]);
Plugin::load('Feedback', ['routes' => true, 'autoload' => true]);
我在几个插件控制器上出错:
Fatal error: Cannot declare class Blog\Controller\AuthorsController, because the name is already in use in /var/www/html/xxx/plugins/Blog/src/Controller/AuthorsController.php on line 0
如果我删除该行:
"Blog\\": "./plugins/Blog/src",
来自composer.json,我得到了cakererror:
Error: Blog.AuthorsController could not be found.
Error: Create the class AuthorsController below in file: /var/www/html/xxx/plugins/Blog/src/Controller/AuthorsController.php
如果我在bootstrap.php中删除了Blog插件的自动加载选项,我会得到与从composer.json中删除行相同的错误。
cakePHP不能自动加载/双重加载控制器会出现什么问题?
检查文件权限,其为AuthorsController的644,为Controller目录的755。
AuthorsController声明如下:
namespace Blog\Controller;
use Blog\Controller\AppController;
class AuthorsController extends AppController {
}