Symfony2 - Custom error pages are never shown

≡放荡痞女 提交于 2019-12-10 23:36:15

问题


I'm trying to customize the error.html.twig, error403.html.twig, error404.html.twig and error500.html.twig, so far i've tried to get the error403.html.twig error caused by an a AccessDeniedExceptionw which is a 403 forbidden, but it displays the custom error page. I created the templates inside app/Resources/TwigBundle/views/Exception like it says here but so far, no luck.

All the templates extend the website base template

403:

    {% extends '::base.html.twig' %}
{% block body %}
<div id="header">
    <a href="{{path ('login')}}" class="fl"><img src="{{ asset('images/access_error.png') }}" alt="TiCad" /></a>
    <div class="fr"><h1>HA OCURRIDO UN ERROR:</h1></div>
    <div align="center">No posee permisos suficientes para acceder a esta seccion, si desea ingresar con otra cuenta haga clic <a href="{{path ('login')}}">AQUI</a></div>
{% endblock %}

404:

{% extends '::base.html.twig' %}
{% block body %}
<div id="header">
    <a href="{{path ('login')}}" class="fl"><img src="{{ asset('images/error404.png') }}" alt="TiCad" /></a>
    <div class="fr"><h1>HA OCURRIDO UN ERROR:</h1></div>
    <div align="center">No encontrado. Por favor, intente de nuevo.</div>
{% endblock %}

500:

{% extends '::base.html.twig' %}
{% block body %}
        <h1><img src="{{ asset('images/internal_server.png') }}" alt="Monse" />Oops! Ha ocurrido un error</h1>
        <h2>Error interno en el servidor</h2>


        <div>
            Algo no funciona. Por favor, Háznos saber que estabas haciendo cuando ocurrio este error, envia un email a <a href="mailto:ticad@icad.com.ve">ticad@icad.com.ve</a>
            Lo arreglaremos lo mas pronto posible. iCad Diseno Inteligente, C.A. se disculpa por los inconvenientes causados. 
        </div>
{% endblock %}

What am i doing wrong?


回答1:


Custom templates won't show in your dev. environment. You can test them using production environment, just make sure to clear the cache.




回答2:


It will throw an error on this line: {% extends '::base.html.twig' %}

You can check your webserver logs; possibly your symfony logs too for the error.

See also:

  • Symfony2 error 500 instead of 404 at production
  • https://github.com/symfony/symfony/issues/5206
  • https://groups.google.com/forum/?fromgroups=#!topic/symfony2/YFeSKgWn4RA

I'm also trying to display the error message within the layout i already have, with no luck so far.




回答3:


Have yo cleared the cache? Also, could you give us the names of your error files?



来源:https://stackoverflow.com/questions/14621663/symfony2-custom-error-pages-are-never-shown

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!