我試圖將用戶轉發到位於另一個包中的自定義404頁面。我修改了我的ExceptionController
並試圖將forward()
頁面發送到我的其他錯誤控制器,該控制器被路由到我的自定義404頁面。Symfony 2 - 無法找到轉發()
我收到的錯誤: 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
我修改文件store\vendor\symfony\symfony\src\Symfony\Bundle\TwigBundle\Controller\ExceptionController.php
。
我已經添加下列行來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,
)
);
}
+1不用修改/ vendor中的文件。無論何時您通過作曲家更新供應商文件,您的更改都將丟失。 – Mike