[英]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.