【问题标题】:Symfony 2 - Get error instead of debug page on test environment / How to set debug to false on test environment (Twig ExceptionController)?Symfony 2 - 在测试环境中获取错误而不是调试页面/如何在测试环境(Twig ExceptionController)上将调试设置为 false?
【发布时间】: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


    【解决方案1】:

    这不是基于环境吗?

    就像在 app_dev.php 中一样:

    $kernel = new AppKernel('stag', TRUE); #TRUE = debug/dev mode on
    $kernel = new AppKernel('stag', FALSE); #FALSE = debug/dev mode off
    

    【讨论】:

    • 感谢 NoScope。它应该基于你所说的,但它不起作用。我会继续研究。
    猜你喜欢
    • 1970-01-01
    • 2015-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-09
    • 1970-01-01
    • 2018-11-14
    • 1970-01-01
    相关资源
    最近更新 更多