我正在尝试创建一个新模块,其中的路由文件指向 Controller 。但我的日志中出现以下错误
ReflectionException: Class \Drupal\glue\Controller\GlueController does not exist in ReflectionMethod->__construct() (line 128 of /home/vagrant/Projects/neut-business-website/core/lib/Drupal/Core/Entity/EntityResolverManager.php).
glue.routing.yml:
hello_world:
path: '/hello-world'
defaults:
_controller: '\Drupal\glue\Controller\GlueController::helloWorldPage'
requirements:
_permission: 'access content'
带有以下 Controller
project_folder/modules/glue/src/Controller/GlueController
<?php
namespace Drupal\glue\Controller;
class GlueController {
public function hellowWorldPage() {
return [
'#markup' => t('<p>Hello world</p>')
];
}
}
最佳答案
我在创建第一个 drupal 8 模块时遇到了类似的错误。我无法找出您案例中的错误,但想分享我案例中的错误。
不知何故,myController.php 文件被放置在
之外/my_module/src/Controller/
文件夹。
将文件移动到正确的目录解决了问题。
也许有一天这会在某个地方节省某人的时间:)
关于php - 未找到 Drupal 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31728616/