从Symfony 2.3升级到2.4后,引发以下异常:
在PageBundle::base.html.twig的第34行呈现模板期间引发异常("呈现片段只能在处理请求时完成。")。
代码正在尝试呈现控制器:
{% if not app.user %}
<div id="login" class="fourcol last">
{{ render(controller("SecurityBundle:Front/Security:login")) }}
</div>
{% endif %}
由于$request为null,fragmentHandler正在引发异常:
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));
}
这种情况也发生在其他树枝渲染函数调用中。
作曲家Symfony组件版本列表:
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
如有任何帮助,将不胜感激
我也有同样的错误,但如果我删除"vendor"文件夹并通过"php composer.phar install"重新命名,一切都会很好。。。
幸运的是,我在其他地方部署了该网站的测试版本,因此我能够比较依赖版本。此错误通过恢复到Symfony 2.3.7解决。以下是更新版本:
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.3.7
2.3.7中FragmentHandler中的呈现方法与2.4.0 中的条件不同
if (null === $this->request) {
throw new 'LogicException('Rendering a fragment can only be done when handling a master Request.');
}
这是在检查是否为空
不确定我是否遇到了同样的问题,但它给了我一个"渲染片段只能在处理请求时完成"的错误。
我通过以下命令重建引导程序解决了这个问题:
php vendor/bundles/Sensio/Bundle/DistributionBundle/Resources/bin/build_bootstrap.php app
另请参阅:Updating Symfony 2.4:"渲染片段只能在处理请求时完成。"