Skip to content

Commit 8e70373

Browse files
committed
Document error page preview in Symfony ~2.6 (#4293)
Feature added in symfony/symfony#12096.
1 parent 39b4430 commit 8e70373

File tree

1 file changed

+55
-11
lines changed

1 file changed

+55
-11
lines changed

cookbook/controller/error_pages.rst

+55-11
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,10 @@ flag. While *exception* pages give you a lot of helpful
4242
information during development, *error* pages are meant to be
4343
shown to the user in production.
4444

45-
.. sidebar:: Testing Error Pages during Development
46-
47-
You should not set ``kernel.debug`` to ``false`` in order to see your
48-
*error* pages during development. This will also stop
49-
Symfony from recompiling your twig templates, among other things.
50-
51-
The third-party `WebfactoryExceptionsBundle`_ provides a special
52-
test controller that allows you to display your custom error
53-
pages for arbitrary HTTP status codes even with
54-
``kernel.debug`` set to ``true``.
45+
.. tip::
5546

56-
.. _`WebfactoryExceptionsBundle`: https://github.com/webfactory/exceptions-bundle
47+
You can also :ref:`preview your error pages <testing-error-pages>`
48+
in ``kernel.debug`` mode.
5749

5850
.. _cookbook-error-pages-by-status-code:
5951

@@ -153,6 +145,53 @@ Refer to the previous section for the order in which the
153145
``exception.html.twig`` for the standard HTML exception page or
154146
``exception.json.twig`` for the JSON exception page.
155147

148+
.. _testing-error-pages:
149+
150+
Testing Error Pages during Development
151+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
152+
153+
The default ``ExceptionController`` also allows you to preview your
154+
*error* pages during development.
155+
156+
.. versionadded:: 2.6
157+
This feature was introduced in Symfony 2.6. Before, the third-party
158+
`WebfactoryExceptionsBundle`_ could be used for the same purpose.
159+
160+
To use this feature, you need to have a definition in your
161+
``routing_dev.yml`` file like so:
162+
163+
.. configuration-block::
164+
165+
.. code-block:: yaml
166+
167+
# app/config/routing_dev.yml
168+
_errors:
169+
resource: "@TwigBundle/Resources/config/routing/errors.xml"
170+
prefix: /_error
171+
172+
If you're coming from an older version of Symfony, you might need to
173+
add this to your ``routing_dev.yml`` file. If you're starting from
174+
scratch, the `Symfony Standard Edition`_ already contains it for you.
175+
176+
With this route added, you can use URLs like
177+
178+
.. code-block:: text
179+
180+
http://localhost/app_dev.php/_error/{statusCode}
181+
http://localhost/app_dev.php/_error/{statusCode}.{format}
182+
183+
to preview the *error* page for a given status code as HTML or for a
184+
given status code and format.
185+
186+
.. tip::
187+
188+
You should not set ``kernel.debug`` to ``false`` in order to see your
189+
error pages during development. This will also stop
190+
Symfony from recompiling your twig templates, among other things.
191+
192+
.. _`WebfactoryExceptionsBundle`: https://github.com/webfactory/exceptions-bundle
193+
.. _`Symfony Standard Edition`: https://github.com/symfony/symfony-standard/
194+
156195
.. _custom-exception-controller:
157196

158197
Replacing the Default ExceptionController
@@ -235,6 +274,11 @@ template to be used.
235274
As of writing, the ``ExceptionController`` is *not* part of the
236275
Symfony API, so be aware that it might change in following releases.
237276

277+
.. tip::
278+
279+
The :ref:`error page preview <testing-error-pages>` also works for
280+
your own controllers set up this way.
281+
238282
.. _use-kernel-exception-event:
239283

240284
Working with the kernel.exception Event

0 commit comments

Comments
 (0)