无法清除 Drupal 8 中的缓存
Cannot clear cache in Drupal 8
我正在做一个简单的 "Hello World" drupal 模块,但它不起作用。
我有 hello_world.info.yml 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'
还有一个 HelloWorldController.php 在 /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')
];
}
}
当我点击 "clear cache" 添加路由和控制器时,我得到:
The website encountered an unexpected error. Please try again later.
在我添加控制器和路由之前不会发生这种情况。
有什么帮助吗?
将您的控制器放入 /src/Controller
而不仅仅是 /src
。
并将所有出现的 helloWorld()
重命名为 content()
并继承 Introductory Drupal 8 routes and controllers example 中的文档。
我正在做一个简单的 "Hello World" drupal 模块,但它不起作用。
我有 hello_world.info.yml 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'
还有一个 HelloWorldController.php 在 /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')
];
}
}
当我点击 "clear cache" 添加路由和控制器时,我得到:
The website encountered an unexpected error. Please try again later.
在我添加控制器和路由之前不会发生这种情况。
有什么帮助吗?
将您的控制器放入 /src/Controller
而不仅仅是 /src
。
并将所有出现的 helloWorld()
重命名为 content()
并继承 Introductory Drupal 8 routes and controllers example 中的文档。