【发布时间】:2013-05-30 10:01:10
【问题描述】:
我想获取错误页面(在应用程序异常被触发后),而不是测试环境中的调试页面。
我跟踪了 Twig Bundle 代码,答案在 findTemplate() 方法中的 Symfony\Bundle\TwigBundle\Controller\ExceptionController 类中。 在这里,我复制了负责选择模板的代码片段。
$name = $debug ? 'exception' : 'error';
if ($debug && 'html' == $format) {
$name = 'exception_full';
}
这段代码没有问题。关键是我无法为我的测试环境将 ExceptionController $debug 变量设置为 false。
基于TwigBundle Configuration Reference,在config_test.yml中将调试参数设置为false就足够了。
twig:
debug: false
这不行。
我浏览了 Symfony 代码并在 vendor/symfony/symfony/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml 上找到了这个片段配置。
<service id="twig.controller.exception" class="%twig.controller.exception.class%">
<argument type="service" id="twig" />
<argument>%kernel.debug%</argument>
</service>
所以,无论我在配置文件中设置什么,调试变量值都不会被修改。
你怎么看?
我正在使用 Symfony 2.2.1,这个问题与 this other question 有关。
【问题讨论】:
标签: symfony