I am trying to forward my users to a custom 404 page which is located in another bundle. I have modified my ExceptionController and attempted to forward() the page to my other Error controller which is routed to my custom 404 page.
I receive the error:
Fatal error: Call to undefined method Symfony\Bundle\TwigBundle\Controller\ExceptionController::forward() in /home/notroot/www/store/vendor/symfony/symfony/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php on line 50
I am modifying the file store\vendor\symfony\symfony\src\Symfony\Bundle\TwigBundle\Controller\ExceptionController.php.
I have added the following lines to ExceptionController.php:
if ($code == '404') {
$response = $this->forward('ItemBundle:Error:pageNotFound');
return $response;
}
ExceptionController.php:
public function showAction(FlattenException $exception, DebugLoggerInterface $logger = null, $format = 'html')
{
$this->container->get('request')->setRequestFormat($format);
$currentContent = $this->getAndCleanOutputBuffering();
$templating = $this->container->get('templating');
$code = $exception->getStatusCode();
if ($code == '404') {
$response = $this->forward('ItemBundle:Error:pageNotFound');
return $response;
}
return $templating->renderResponse(
$this->findTemplate($templating, $format, $code, $this->container->get('kernel')->isDebug()),
array(
'status_code' => $code,
'status_text' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '',
'exception' => $exception,
'logger' => $logger,
'currentContent' => $currentContent,
)
);
}
I replaced the
forward()function with the shortcut it points to as stated in the docs.