douchiwan1503
2018-04-16 10:21
浏览 241
已采纳

无法在Drupal 8中清除缓存

I am doing a simple "Hello World" drupal module but it doesn't work.

I have the hello_world.info.yml in drupal/web/modules/custom/hello_world

The modules is installed and working.

Now I added a hello_world.routing.yml with this code:

hello_world.hello:
  path: '/hello'
  defaults:
    _controller:
'\Drupal\hello_world\Controller\HelloWorldController::helloWorld'
  _title: 'Our first route'
requirements:
  _permission: 'access content'

And a HelloWorldController.php in /src:

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')
    ];
  }
}

When I click on "clear cache" so the routing and the controller are added, I get:

The website encountered an unexpected error. Please try again later.

This does not happen before I added the controller and routing.

Any help?

图片转代码服务由CSDN问答提供 功能建议

我正在做一个简单的“Hello World”drupal模块,但它不起作用。

我在 drupal / web / modules / custom / hello_world中有hello_world.info.yml

模块已安装并正常工作。

现在我添加了一个带有以下代码的hello_world.routing.yml:

  hello_world.hello:
 path:'/ hello'
 默认值:
 _controller:
'\ Drupal \ hello_world \ Controller \ HelloWorldController :: helloWorld'
 _title:'我们的第一条路线'
requirements:
 _permission:'access content'
   
 
 

/ src中的HelloWorldController.php:

 命名空间Drupal \ hello_world \ Controller; 
use Drupal \ Core \ Controller \ ControllerBase; 
  / ** 
 *致敬消息的控制器。
 * / 
class HelloWorldController扩展ControllerBase {
 / ** 
 * Hello World。
 * 
 * @return string 
 * / 
 n public function  helloWorld(){
 return [
'#markup'=>  $ this-> t('Hello World')
]; 
} 
} 
   
 
 

当我点击“清除缓存”时所以路由 并添加控制器,我得到:

 网站遇到意外错误。 请稍后重试。
   
 
 

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

有任何帮助吗?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dsfdsf21321 2018-04-16 10:39
    已采纳

    Put your controller into /src/Controller not just /src.

    And rename all occurrences of helloWorld() to content() and inherit docs as in Introductory Drupal 8 routes and controllers example.

    打赏 评论

相关推荐 更多相似问题