Custom symfony error pages for 404 and 500 errors

500 error page
- Since symfony 1.2 your error page must be stored as error.html.php in the folder /config/errors/
- Default file:/lib/vendor/symfony/lib/exception/data/error.html.php
Available variables:  (một số biến được dùng trong file error)
- $exception: The exception.
- $code: The status code. Defaults to 500 but might have been replaced by $response->getStatusCode().
- $text: The status text. Defaults to “Internal server error” but might have been replaced by $response->getStatusText().
- $format: The request format. Defaults to “html” but might have been replaced by $response->getRequestFormat().

404 error page
404 errors are handled by the symfony default module. So you can simply override the template for the action error404 in this module. To do this simply create a folder default/templates in the modules folder of your application and save your 404 error template as error404Success.php. As this is a normal template it will be rendered with your default layout.
Alternatively you can also use your own module for handling the 404 errors. If you want to do so, you need to tell symfony about it in the settings.yml of your application:
  all:
.actions
error_404_module: my_error_module
error_404_action: my_error_action
Available variables
A 404 page is created by throwing a sfError404Exception which then forwards to sfConfig::get(‘sf_error_404_module’), sfConfig::get(‘sf_error_404_action’). Thus you can access thestandard view variables like $sf_context, $sf_response etc.Unfortunately there seems to be no way to access the original exception message (Ticket 5216).
These custom error pages are only displayed in the prod environment. It also possible to customize the error pages for the dev environment, but that should rarely be necessary.
Refer: http://symfony.com/legacy/doc/cookbook/1_2/en/error_templates

No comments:

Post a Comment