Php Can';t覆盖Symfony2中的默认异常控制器
我正在尝试覆盖默认的异常控制器。我试着按照官方的Symfony 2食谱来做,也尝试了 我采取了以下步骤:Php Can';t覆盖Symfony2中的默认异常控制器,php,symfony,Php,Symfony,我正在尝试覆盖默认的异常控制器。我试着按照官方的Symfony 2食谱来做,也尝试了 我采取了以下步骤: 在我的bundle(Ed)中,我创建了名为MyExceptionController.php的新控制器文件: <?php use Symfony\Bundle\TwigBundle\Controller\ExceptionController; class MyExceptionController extends ExceptionController { //over
MyExceptionController.php的新控制器文件:
<?php
use Symfony\Bundle\TwigBundle\Controller\ExceptionController;
class MyExceptionController extends ExceptionController
{
//override the showAction() or findTemplate() method here
public function showAction($token)
{
if (null === $this->profiler) {
throw new NotFoundHttpException('The profiler must be enabled.');
}
$this->profiler->disable();
$exception = $this->profiler->loadProfile($token)->getCollector('exception')->getException();
$template = $this->getTemplate();
if (!$this->twig->getLoader()->exists($template)) {
$handler = new ExceptionHandler();
return new Response($handler->getContent($exception), 200, array('Content-Type' => 'text/html'));
}
$code = $exception->getStatusCode();
$name = "Mark";
return new Response($this->twig->render(
$template,
array(
'status_code' => $code,
'status_text' => Response::$statusTexts[$code],
'exception' => $exception,
'logger' => null,
'currentContent' => '',
'name' => $name,
)
), 200, array('Content-Type' => 'text/html'));
}
}
Fatal error: Class 'EdProfileBundle\Controller\MyExceptionController' not found in (..)\app\cache\prod\appProdDebugProjectContainer.php on line 2951
config.yml
中的名称/位置是否有问题(例如:我是否必须将twig.controller.exception
更改为smth-else?),或者问题出在其他地方?尝试使用参数:[“@twig”,“%kernel.debug%”而不是参数:[@twig,%kernel.debug%]
尝试:类:\EdProfileBundle\Controller\MyExceptionController
我收到以下错误:\EdProfileBundle\\Controller\\MyExceptionController'”不是“twig.Controller.exception”的有效类名“服务您的控制器
类中缺少命名空间
。添加命名空间EdProfileBundle\ControllerFatal error: Class 'EdProfileBundle\Controller\MyExceptionController' not found in (..)\app\cache\prod\appProdDebugProjectContainer.php on line 2951