Symfony 2.4 在 TWIG 中渲染控制器抛出“渲染片段只能在处理请求时完成".例外 [英] Symfony 2.4 Rendering a controller in TWIG throws "Rendering a fragment can only be done when handling a Request." Exception
问题描述
从 Symfony 2.3 升级到 2.4 后,抛出以下异常:
在第 34 行的 PageBundle::base.html.twig 中渲染模板期间抛出异常(渲染片段只能在处理请求时完成.").
代码正在尝试渲染控制器:
{% 如果不是 app.user %}<div id="login" class="fourcol last">{{ render(controller("SecurityBundle:Front/Security:login")) }}
{% 万一 %}
fragmentHandler 抛出异常,因为 $request 为空:
public function render($uri, $renderer = 'inline', array $options = array()){如果 (!isset($options['ignore_errors'])) {$options['ignore_errors'] = !$this->debug;}如果 (!isset($this->renderers[$renderer])) {throw new \InvalidArgumentException(sprintf('%s"渲染器不存在.', $renderer));}如果 (!$request = $this->getRequest()) {throw new \LogicException('渲染片段只能在处理请求时完成.');}var_dump($request);死();return $this->deliver($this->renderers[$renderer]->render($uri, $request, $options));}
这也发生在其他树枝渲染函数调用上.
来自 composer 的 Symfony 组件版本列表:
symfony/assetic-bundle v2.3.0symfony/icu v1.2.0symfony/monolog-bundle v2.3.0symfony/swiftmailer-bundle v2.3.4symfony/symfony v2.4.0
任何帮助将不胜感激
我有同样的错误,但如果我删除vendor"文件夹并通过php composer.phar install"重新启动它,一切正常...
After upgrading from Symfony 2.3 to 2.4, the following exception is being thrown:
An exception has been thrown during the rendering of a template ("Rendering a fragment can only be done when handling a Request.") in PageBundle::base.html.twig at line 34.
The code is trying to render a controller:
{% if not app.user %}
<div id="login" class="fourcol last">
{{ render(controller("SecurityBundle:Front/Security:login")) }}
</div>
{% endif %}
The exception is being thrown by fragmentHandler because $request is null:
public function render($uri, $renderer = 'inline', array $options = array())
{
if (!isset($options['ignore_errors'])) {
$options['ignore_errors'] = !$this->debug;
}
if (!isset($this->renderers[$renderer])) {
throw new \InvalidArgumentException(sprintf('The "%s" renderer does not exist.', $renderer));
}
if (!$request = $this->getRequest()) {
throw new \LogicException('Rendering a fragment can only be done when handling a Request.');
}
var_dump($request); die();
return $this->deliver($this->renderers[$renderer]->render($uri, $request, $options));
}
This is also happening on other twig render function calls.
List of Symfony component versions from composer:
symfony/assetic-bundle v2.3.0
symfony/icu v1.2.0
symfony/monolog-bundle v2.3.0
symfony/swiftmailer-bundle v2.3.4
symfony/symfony v2.4.0
Any help would be greatly appreciated
i have the same error, but if i delete the "vendor" folder and reinit it via "php composer.phar install", all works fine...
这篇关于Symfony 2.4 在 TWIG 中渲染控制器抛出“渲染片段只能在处理请求时完成".例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!