Skip to content

Commit 9f9d586

Browse files
committed
minor #6224 Note to create a service if you extend ExceptionController (pamuche)
This PR was submitted for the 3.0 branch but it was merged into the 2.3 branch instead (closes #6224). Discussion ---------- Note to create a service if you extend ExceptionController I had some trouble to get the custom exception handling with inheritance of ExceptionController working, because I hadn't a clue to make a service out of the ExceptionController of the TwigBundle. Commits ------- fff23f7 Note to create a service if you extend ExceptionController
2 parents d2c3e26 + fff23f7 commit 9f9d586

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

cookbook/controller/error_pages.rst

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,25 @@ will be passed two parameters:
217217
Instead of creating a new exception controller from scratch you can, of course,
218218
also extend the default :class:`Symfony\\Bundle\\TwigBundle\\Controller\\ExceptionController`.
219219
In that case, you might want to override one or both of the ``showAction()`` and
220-
``findTemplate()`` methods. The latter one locates the template to be used.
220+
``findTemplate()`` methods. The latter one locates the template to be used.
221+
222+
.. note::
223+
224+
In case of extending the :class:`Symfony\\Bundle\\TwigBundle\\Controller\\ExceptionController`
225+
you may configure a service to pass the Twig environment and the ``debug`` flag to the constructor.
226+
227+
.. configuration-block::
228+
229+
.. code-block:: yaml
230+
231+
# app/config/config.yml
232+
services:
233+
app.extension_controller:
234+
class: AppBundle\CustomExceptionController
235+
arguments: [ "@twig", "%kernel.debug%" ]
236+
237+
twig:
238+
exception_controller: app.extension_controller:showAction
221239
222240
.. _use-kernel-exception-event:
223241

0 commit comments

Comments
 (0)