简体   繁体   English

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

[英]Symfony2 - Blank pages on php errors and 404's

In my production environment, symfony2 is showing a blank page on 404's and a 503 Service Unavailable on general php errors. 在我的生产环境中,symfony2在404上显示空白页面,在一般php错误上显示503服务不可用。

I have custom TwigTemplates under app/Resources/TwigBundle/views/Exception/error|error404|error500.html.twig 我在app / Resources / TwigBundle / views /异常/错误| error404 | error500.html.twig下有自定义TwigTemplates

When looking in the apache error log, it is showing the error correctly, but no sign of why it is not loading the error template. 查看apache错误日志时,它正确显示错误,但没有迹象表明它没有加载错误模板。

Does anybody have an idea how to solve this? 有没有人知道如何解决这个问题?

清除缓存:

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

On a blank page, and a correct html status code, most likely the base template is not being extended correctly. 在空白页面上,以及正确的html状态代码,很可能基本模板未正确扩展。 in my case block content was not specified in my error template. 在我的情况下,我的错误模板中未指定块内容。

Error template 错误模板

{#  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 %}

And the base template 和基础模板

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

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

Í would run the application under ´dev´ environment, see where the error is and later switch the environment back. Í将在'dev'环境下运行应用程序,查看错误的位置,然后再切换回环境。

In web/app.php change from 在web / app.php中更改

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

to

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

You'll be able to see an error in a browser. 您将能够在浏览器中看到错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM