Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As shown in <a href="http://symfony.com/doc/current/cookbook/controller/error_pages.html">the Symfony Cookbook</a> you can override error pages in two ways:</p> <ul> <li>Overriding the templates</li> <li>Using a custom exception controller</li> </ul> <p>If you only want to show the <code>/sitemap</code> route on a 404 (<code>HttpNotFoundException</code>) exception you could override the Twig exception template by creating a new template in <code>app/Resources/TwigBundle/views/Exception/error404.html.twig</code>.</p> <p>Another way that is not shown in the cookbook is using an event listener. When the kernel encounters an exception, a <a href="http://symfony.com/doc/2.0/book/internals.html#kernel-exception-event"><code>kernel.exception</code></a> event is dispatched. By default, this exception is caught by the exception listening provided by Twig. You can <a href="http://symfony.com/doc/master/cookbook/service_container/event_listener.html">create your own event listener</a> which listens for the <code>kernel.exception</code> event and renders a page:</p> <pre><code>&lt;?php use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; use Symfony\Component\HttpFoundation\Response; public function onKernelException(GetResponseForExceptionEvent $event) { if ($event-&gt;getException() instanceof NotFoundHttpException) { $response = $this-&gt;templating-&gt;renderResponse(/* sitemap */); $event-&gt;setResponse($response) } } </code></pre> <p>(I haven't tested this code, so you should try it yourself! And you have to inject the templating service into the event listener yourself, of course).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload