无法在Drupal 8中清除缓存

时间:2018-04-16 10:21:53

标签: php drupal drupal-8

我正在做一个简单的“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.

在添加控制器和路由之前,这不会发生。

任何帮助?

1 个答案:

答案 0 :(得分:3)

将您的控制器置于/src/Controller而不只是/src

并将所有helloWorld()重命名为content()并继承Introductory Drupal 8 routes and controllers example中的文档。