无法在Drupal 8中清除缓存(Cannot clear cache in Drupal 8)

编程入门 行业动态 更新时间:2024-10-17 21:15:42
无法在Drupal 8中清除缓存(Cannot clear cache in Drupal 8)

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

我在drupal/web/modules/custom/hello_world

模块已安装并正常工作。

现在我用这段代码添加了一个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.

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

有帮助吗?

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?

最满意答案

将控制器放入/src/Controller而不仅仅是/src 。

并将所有出现的helloWorld()重命名为content()并继承文档,如引言Drupal 8路由和控制器示例中所示 。

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.

更多推荐

本文发布于:2023-07-25 05:43:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1256801.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:缓存   Drupal   cache   clear

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!