【发布时间】:2018-04-16 10:21:53
【问题描述】:
我正在做一个简单的“Hello World”drupal 模块,但它不起作用。
我有 drupal/web/modules/custom/hello_world 中的 hello_world.info.yml
模块已安装并正在运行。
现在我用这段代码添加了一个 hello_world.routing.yml:
hello_world.hello:
path: '/hello'
defaults:
_controller:
'\Drupal\hello_world\Controller\HelloWorldController::helloWorld'
_title: 'Our first route'
requirements:
_permission: 'access content'
还有一个 /src 中的 HelloWorldController.php:
namespace Drupal\hello_world\Controller;
use Drupal\Core\Controller\ControllerBase;
/**
* Controller for the salutation message.
*/
class HelloWorldController extends ControllerBase {
/**
* Hello World.
*
* @return string
*/
public function helloWorld() {
return [
'#markup' => $this->t('Hello World')
];
}
}
当我点击“清除缓存”以添加路由和控制器时,我得到:
The website encountered an unexpected error. Please try again later.
这在我添加控制器和路由之前不会发生。
有什么帮助吗?
【问题讨论】: