From 8e932f8f6e17996b02f21bc62a29a292687d4a00 Mon Sep 17 00:00:00 2001 From: pamuche Date: Thu, 4 Feb 2016 15:28:00 +0100 Subject: [PATCH 1/3] 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. --- cookbook/controller/error_pages.rst | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/cookbook/controller/error_pages.rst b/cookbook/controller/error_pages.rst index 61c7769a5dc..ae8968399f3 100644 --- a/cookbook/controller/error_pages.rst +++ b/cookbook/controller/error_pages.rst @@ -251,7 +251,25 @@ will be passed two parameters: Instead of creating a new exception controller from scratch you can, of course, also extend the default :class:`Symfony\\Bundle\\TwigBundle\\Controller\\ExceptionController`. In that case, you might want to override one or both of the ``showAction()`` and -``findTemplate()`` methods. The latter one locates the template to be used. +``findTemplate()`` methods. The latter one locates the template to be used. + +.. note:: + + In case of extending the :class:`Symfony\\Bundle\\TwigBundle\\Controller\\ExceptionController` + you may configure a service to pass the twig-Environment and the debug-Flag to the constructor. + + .. configuration-block:: + + .. code-block:: yaml + + # app/config/config.yml + services: + my_custom_exception_controller_service: + class: AppBundle\CustomExceptionController + arguments: [ "@twig", "%kernel.debug%" ] + + twig: + exception_controller: my_custom_exception_controller_service:showAction .. tip:: From 0ecf2e0614c20140a3af77b74daf802f92d1192f Mon Sep 17 00:00:00 2001 From: Robert Clochard Date: Fri, 5 Feb 2016 19:42:07 +0100 Subject: [PATCH 2/3] Integrate recommended changes Thank you for your recommendations. It helps me to contribute better additions to the docs in the future. --- cookbook/controller/error_pages.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cookbook/controller/error_pages.rst b/cookbook/controller/error_pages.rst index ae8968399f3..21b6444d9de 100644 --- a/cookbook/controller/error_pages.rst +++ b/cookbook/controller/error_pages.rst @@ -256,7 +256,7 @@ In that case, you might want to override one or both of the ``showAction()`` and .. note:: In case of extending the :class:`Symfony\\Bundle\\TwigBundle\\Controller\\ExceptionController` - you may configure a service to pass the twig-Environment and the debug-Flag to the constructor. + you may configure a service to pass the Twig environment and the ``debug`` flag to the constructor. .. configuration-block:: @@ -264,7 +264,7 @@ In that case, you might want to override one or both of the ``showAction()`` and # app/config/config.yml services: - my_custom_exception_controller_service: + app.extension_controller: class: AppBundle\CustomExceptionController arguments: [ "@twig", "%kernel.debug%" ] From e80cf46d9ca1ce7f349ff2da5bc7303e95150d3e Mon Sep 17 00:00:00 2001 From: Robert Clochard Date: Fri, 5 Feb 2016 19:45:53 +0100 Subject: [PATCH 3/3] Adds one forgotten change --- cookbook/controller/error_pages.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cookbook/controller/error_pages.rst b/cookbook/controller/error_pages.rst index 21b6444d9de..4823739c8a4 100644 --- a/cookbook/controller/error_pages.rst +++ b/cookbook/controller/error_pages.rst @@ -269,7 +269,7 @@ In that case, you might want to override one or both of the ``showAction()`` and arguments: [ "@twig", "%kernel.debug%" ] twig: - exception_controller: my_custom_exception_controller_service:showAction + exception_controller: app.extension_controller:showAction .. tip::