【发布时间】:2015-06-13 10:10:57
【问题描述】:
我正在尝试使用我的控制器渲染模板但不起作用 它告诉我这个错误:
LogicException:控制器必须返回响应(
你好 Bob!
给出)。在 Symfony\Component\HttpKernel\HttpKernel->handleRaw() (core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/HttpKernel.php 的第 163 行)。
我的功能:
public function helloAction($name) {
$twigFilePath = drupal_get_path('module', 'acme') . '/templates/hello.html.twig';
$template = $this->twig->loadTemplate($twigFilePath);
return $template->render(array('name' => $name));
}
【问题讨论】:
-
您需要返回一个响应对象,而不是模板生成的字符串。
return new Response($template->render(array('name' => $name)));应该为你做,虽然我不能确定,因为我只使用了模板组件作为 Symfony 框架的一部分。 -
@Qoop 它的工作原理 thnks
标签: php symfony drupal drupal-8