@@ -42,18 +42,10 @@ flag. While *exception* pages give you a lot of helpful
42
42
information during development, *error * pages are meant to be
43
43
shown to the user in production.
44
44
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.
45
+ .. tip ::
50
46
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 ``.
55
-
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.
57
49
58
50
.. _cookbook-error-pages-by-status-code :
59
51
@@ -153,6 +145,70 @@ Refer to the previous section for the order in which the
153
145
``exception.html.twig `` for the standard HTML exception page or
154
146
``exception.json.twig `` for the JSON exception page.
155
147
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
+ .. code-block :: xml
173
+
174
+ <!-- app/config/routing_dev.xml -->
175
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
176
+ <routes xmlns =" http://symfony.com/schema/routing"
177
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
178
+ xsi : schemaLocation =" http://symfony.com/schema/routing
179
+ http://symfony.com/schema/routing/routing-1.0.xsd" >
180
+
181
+ <import resource =" @TwigBundle/Resources/config/routing/errors.xml"
182
+ prefix =" /_error" />
183
+ </routes >
184
+
185
+ .. code-block :: php
186
+
187
+ // app/config/routing_dev.php
188
+ use Symfony\Component\Routing\RouteCollection;
189
+
190
+ $collection = new RouteCollection();
191
+ $collection->addCollection(
192
+ $loader->import("@AcmeHelloBundle/Resources/config/routing.php")
193
+ );
194
+ $collection->addPrefix("/error");
195
+
196
+ return $collection;
197
+
198
+ If you're coming from an older version of Symfony, you might need to
199
+ add this to your ``routing_dev.yml `` file. If you're starting from
200
+ scratch, the `Symfony Standard Edition `_ already contains it for you.
201
+
202
+ With this route added, you can use URLs like
203
+
204
+ .. code-block :: text
205
+
206
+ http://localhost/app_dev.php/_error/{statusCode}
207
+ http://localhost/app_dev.php/_error/{statusCode}.{format}
208
+
209
+ to preview the *error * page for a given status code as HTML or for a
210
+ given status code and format.
211
+
156
212
.. _custom-exception-controller :
157
213
158
214
Replacing the Default ExceptionController
@@ -235,6 +291,11 @@ template to be used.
235
291
As of writing, the ``ExceptionController `` is *not * part of the
236
292
Symfony API, so be aware that it might change in following releases.
237
293
294
+ .. tip ::
295
+
296
+ The :ref: `error page preview <testing-error-pages >` also works for
297
+ your own controllers set up this way.
298
+
238
299
.. _use-kernel-exception-event :
239
300
240
301
Working with the kernel.exception Event
@@ -285,4 +346,6 @@ several) listeners deal with them.
285
346
286
347
Good luck!
287
348
349
+ .. _`WebfactoryExceptionsBundle` : https://github.com/webfactory/exceptions-bundle
350
+ .. _`Symfony Standard Edition` : https://github.com/symfony/symfony-standard/
288
351
.. _`ExceptionListener` : https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php
0 commit comments