14

I want to work on the 404 page from the dev environment. I customize 404 using this file : app/Resources/TwigBundle/views/Exception/error.html.twig

This prod url work correctly : mysite.com/404

But this one mysite.com/app_dev.php/404 throw a NotFoundHttpException and give me the dev debug page.

Is it possible to display the error page instead of debug page ?

UPDATE:

The official documentation has now a chapter about that : Testing Error Pages during Development

Vivien
  • 1,159
  • 2
  • 14
  • 34

4 Answers4

22

To display error pages, in web/app_dev.php change second parameter to false

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

After testing what you need, change it back.


UPDATE

Thanks @user2019515 for pointing that out - now (2.3 and up) there's a link to WebfactoryExeptionsBundle in Symfony docs and the method I wrote above should not be used.

Karmalakas
  • 1,143
  • 2
  • 19
  • 39
  • This is definitely the way to go if you want to test your error pages in dev env, as they will be in prod. – ftassi Feb 04 '14 at 10:07
  • 1
    According to the docs, you shouldn't do this: http://symfony.com/doc/current/cookbook/controller/error_pages.html – user2019515 Jun 14 '14 at 03:13
  • Thanks for pointing that out, @user2019515. Though, I can't remember now for sure, but when I wrote this answer, there weren't in docs about WebfactoryExceptionsBundle - it appeared with 2.3 documentation. – Karmalakas Jun 14 '14 at 08:45
19

As of Symfony2.6 in dev environment, you can use the following route:

/_error/404.html

Where 404 is the error code to test and html the format of the request. To be able to use this features, make sure you have the following entry in your routing_dev.yml file:

# app/config/routing_dev.yml
_errors:
    resource: "@TwigBundle/Resources/config/routing/errors.xml"
    prefix:   /_error
COil
  • 7,201
  • 2
  • 50
  • 98
14

You need to override the exception_full.html.twig template on development.

app/Resources/TwigBundle/views/Exception/exception_full.html.twig

Symfony2 uses this template to provide you with as much debugging information as possible during development.

When the kernel is in debug mode, Symfony2 will use exception_full.html.twig, otherwise it will use the specific templates you override.

See vendor/symfony/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php, specifically the showAction() and findTemplate() functions for more details.

Chris McKinnel
  • 14,694
  • 6
  • 64
  • 67
1

Also you can add routes to your routing_dev.yml file

error404:
    path: /404
    defaults:
        _controller: FrameworkBundle:Template:template
        template:    TwigBundle:Exception:error404.html.twig

error500:
    path: /500
    defaults:
        _controller: FrameworkBundle:Template:template
        template:    TwigBundle:Exception:error500.html.twig
Vladimir Pak
  • 658
  • 1
  • 9
  • 13