Symfony2 - 关于 php 错误和 404 的空白页

Symfony2 - Blank pages on php errors and 404's

在我的生产环境中,symfony2 在 404 上显示空白页面,在一般 php 错误上显示 503 服务不可用。

我在 app/Resources/TwigBundle/views/Exception/error|error404|error500.html.twig

下有自定义 TwigTemplates

查看 apache 错误日志时,它正确地显示了错误,但没有迹象表明为什么它没有加载错误模板。

有人知道如何解决这个问题吗?

清除缓存:

php app/console cache:clear --env=prod --no-debug

Í 会 运行 ‘dev’ 环境下的应用程序,看看错误在哪里,然后切换回环境。

在web/app.php中从

变化
$kernel = new AppKernel('prod', false);

$kernel = new AppKernel('dev', false);

您将能够在浏览器中看到错误。

在空白页面上,以及正确的 html 状态代码,很可能是基本模板未正确扩展。在我的例子中,块内容没有在我的错误模板中指定。

错误模板

{#  app/Resources/Twig/views/Exception/error.html.twig #}

{% extends 'MyUIBundle::error.html.twig' %}

{% block content %}

    <!-- begin error -->
    <div class="error">
        <!-- error content -->
    </div>
    <!-- end error -->

{% endblock %}

和基础模板

{#  MyUIBundle::error.html.twig #}

<body>
    <!-- begin #page-container -->
    <div id="page-container">
        {% block content '' %}
    </div>
    <!-- end #page-container -->
</body>