简体   繁体   中英

How to add custom error page Symfony 3

I have tried as documentation says:

app/
└─ Resources/
   └─ TwigBundle/
      └─ views/
         └─ Exception/
            ├─ error404.html.twig
            ├─ error403.html.twig
            ├─ error.html.twig      # All other HTML errors (including 500)
            ├─ error404.json.twig
            ├─ error403.json.twig
            └─ error.json.twig      # All other JSON errors (including 500)

But none of those shows the custom page on prod env. Then I tried to add in the same Exception folder a exception.html.twig file and it work for all the errors (404, 500, ...), but it shows it in dev, so I can't see the error when developing if I have that file. And inside the production env it shows always the red screen

在此处输入图片说明

So what's the proper way to make a custom error page to production and how to test it?

Error pages are not used in development environment. During development, it shows an other error page with more debug information (which may contain information you don't want to expose public). The Symfony header bar is not showed in production by default.

To see how the error pages look like in production, try Error page previews :

# app/config/routing_dev.yml
_errors:
    resource: "@TwigBundle/Resources/config/routing/errors.xml"
    prefix:   /_error

If your production environment shows the Symfony Exception page, make sure the debug flag is set to false in app.php :

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

I think the answer for your question is about clear cache.
use this command :
$php bin/console cache:clear --no-warmup --env=prod
and you will get your Error pages,
Good luck.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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