I am building an administration panel for a website and I would like to change the view called when a 404 exception occurs but only for the admin application. <
You could try this one:
public function __construct(TwigEngine $templating)
{
$this->templating = $templating;
}
public function onKernelException(GetResponseForExceptionEvent $event)
{
static $handling;
$exception = $event->getException();
if (true === $handling) {
return;
}
$handling = true;
$code = $exception->getCode();
if (0 !== strpos($event->getRequest()->getPathInfo(), '/admin') && 404 === $code) {
$message = $this->templating->render('AcmeBundle:Default:error404new.html.twig', array());
$response = new Response($message, $code);
$event->setResponse($response);
}
$handling = false;
}
$templating variable can be passed in services.xml: