[英]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.
在添加控制器和路由之前,这不会发生。
有帮助吗?
将控制器放入/src/Controller
而不仅仅是/src
。
并将所有出现的helloWorld()
重命名为content()
并继承文档,如引入Drupal 8路由和控制器示例中所述 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.