Symfony 2-找不到转发()
我正在尝试将我的用户转发到另一个捆绑包中的自定义404页面。我已修改了我的Symfony 2-找不到转发(),symfony,Symfony,我正在尝试将我的用户转发到另一个捆绑包中的自定义404页面。我已修改了我的例外控制器,并尝试将页面转发到另一个错误控制器,该控制器被路由到我的自定义404页面 我收到错误消息: 致命错误:第50行/home/notroot/www/store/vendor/Symfony/Symfony/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php中调用未定义的方法Symfony\Bundle\Controller\Except
例外控制器
,并尝试将页面转发到另一个错误控制器
,该控制器被路由到我的自定义404页面
我收到错误消息:
致命错误:第50行/home/notroot/www/store/vendor/Symfony/Symfony/src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php中调用未定义的方法Symfony\Bundle\Controller\ExceptionController::forward()
我正在修改文件store\vendor\symfony\symfony\src\symfony\Bundle\TwigBundle\Controller\ExceptionController.php
我已将以下行添加到ExceptionController.php中:
if ($code == '404') {
$response = $this->forward('ItemBundle:Error:pageNotFound');
return $response;
}
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,
)
);
}
ExceptionController.php:
if ($code == '404') {
$response = $this->forward('ItemBundle:Error:pageNotFound');
return $response;
}
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,
)
);
}
Symfony/Bundle/TwigBundle/Controller/ExceptionController
不扩展通常在用户Bundle中使用的框架控制器。另外,直接编辑存储在供应商
目录中的任何内容也不是一个好主意。Symfony/Bundle/TwigBundle/Controller/ExceptionController没有扩展通常在用户Bundle中使用的框架控制器。另外,直接编辑存储在供应商
目录中的任何内容也不是一个好主意。我用它指向的快捷方式替换了forward()
函数,如中所述
我用它指向的快捷方式替换了
forward()
函数,如中所述
+1用于不修改/供应商中的文件。任何时候通过composer更新供应商文件时,您所做的更改都将丢失。+1表示不在/vendor中修改文件。任何时候,当您通过composer更新供应商文件时,您所做的更改都将丢失。