From 56809cdc5f961b711ff11bfe9eb77673d5839a53 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Sat, 5 Jul 2014 14:36:32 -0500 Subject: [PATCH 1/2] Adding the capability to add ?_real_template=1 to an exception page to see the error template --- .../Bundle/TwigBundle/Controller/ExceptionController.php | 8 +++++++- .../Resources/views/Exception/exception_full.html.twig | 6 ++++++ .../Bundle/TwigBundle/Resources/views/layout.html.twig | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php b/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php index e0acb565648fb..b9fb516bbfe47 100644 --- a/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php +++ b/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php @@ -51,8 +51,14 @@ public function showAction(Request $request, FlattenException $exception, DebugL $code = $exception->getStatusCode(); + // allow the developer to see the real template with ?_real_template=1 + $debug = $this->debug; + if ($debug && $request->query->get('_real_template')) { + $debug = false; + } + return new Response($this->twig->render( - $this->findTemplate($request, $_format, $code, $this->debug), + $this->findTemplate($request, $_format, $code, $debug), array( 'status_code' => $code, 'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '', diff --git a/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception_full.html.twig b/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception_full.html.twig index 1920b6008b117..62e8693678492 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception_full.html.twig +++ b/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception_full.html.twig @@ -11,3 +11,9 @@ {% block body %} {% include 'TwigBundle:Exception:exception.html.twig' %} {% endblock %} + +{% block header_right %} + + Render True Error Page + +{% endblock %} diff --git a/src/Symfony/Bundle/TwigBundle/Resources/views/layout.html.twig b/src/Symfony/Bundle/TwigBundle/Resources/views/layout.html.twig index 69409827057d0..b98913f57743c 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/views/layout.html.twig +++ b/src/Symfony/Bundle/TwigBundle/Resources/views/layout.html.twig @@ -31,6 +31,8 @@ + + {% block header_right %}{% endblock %} From afa16cb7f367376ea9d8fd6e1d5cdfa0b459d661 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Sat, 23 Aug 2014 11:49:29 -0400 Subject: [PATCH 2/2] Padding "original_request" to the exception controller and using it This *only* shows the "Render True Error Page" if the request is GET. Additionally, it keeps the original query parameters in tact --- .../Controller/ExceptionController.php | 17 ++++++++++++++++- .../views/Exception/exception_full.html.twig | 9 ++++++++- .../EventListener/ExceptionListener.php | 1 + 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php b/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php index b9fb516bbfe47..8afab1ca81d49 100644 --- a/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php +++ b/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php @@ -51,12 +51,25 @@ public function showAction(Request $request, FlattenException $exception, DebugL $code = $exception->getStatusCode(); + $originalRequest = $request->attributes->get('original_request'); + // allow the developer to see the real template with ?_real_template=1 $debug = $this->debug; - if ($debug && $request->query->get('_real_template')) { + if ($debug && $originalRequest && $originalRequest->query->get('_real_template')) { $debug = false; } + // determine if we're able to show the link to view the true error template + $showErrorTemplateLink = false; + $errorTemplateParams = array(); + if ($originalRequest && $originalRequest->isMethod('GET')) { + $showErrorTemplateLink = true; + $errorTemplateParams = array_merge( + $request->query->all(), + array('_real_template' => 1) + ); + } + return new Response($this->twig->render( $this->findTemplate($request, $_format, $code, $debug), array( @@ -65,6 +78,8 @@ public function showAction(Request $request, FlattenException $exception, DebugL 'exception' => $exception, 'logger' => $logger, 'currentContent' => $currentContent, + 'showErrorTemplateLink' => $showErrorTemplateLink, + 'errorTemplateParams' => $errorTemplateParams, ) )); } diff --git a/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception_full.html.twig b/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception_full.html.twig index 62e8693678492..9b0c0d54bc35a 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception_full.html.twig +++ b/src/Symfony/Bundle/TwigBundle/Resources/views/Exception/exception_full.html.twig @@ -13,7 +13,14 @@ {% endblock %} {% block header_right %} + {% if showErrorTemplateLink %} - Render True Error Page + + Render True Error Page + + {% endif %} {% endblock %} diff --git a/src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php b/src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php index 3450b6210ce07..b51a15cd7abbf 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php @@ -114,6 +114,7 @@ protected function duplicateRequest(\Exception $exception, Request $request) '_controller' => $this->controller, 'exception' => FlattenException::create($exception), 'logger' => $this->logger instanceof DebugLoggerInterface ? $this->logger : null, + 'original_request' => $request, // keep for BC -- as $format can be an argument of the controller callable // see src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php // @deprecated in 2.4, to be removed in 3.0