我刚刚将Symfony 2.7页面更新为2.8。除了Symfony本身之外,还更新了许多其他软件包(例如FOSUserBundle
,FOSRestBundle
,Doctrine
等)。
更新后,CustomExceptionController
不再有效。像404或500这样的错误显示默认的异常页面而不是我的自定义页面。在更新之前,CustomExceptionController
没有任何问题。
这是配置:
// app/config/config.yml
...
twig:
exception_controller: app.exception_controller:showAction
// src/MyAppBundle/Resources/config/services.yml
app.exception_controller:
class: MyAppBundle\Controller\CustomExceptionController
arguments: ['@twig', '%kernel.debug%', "@translator.default" ]
// src/MyAppBundle/Controller/CustomExceptionController.php
use Symfony\Component\Debug\Exception\FlattenException;
//use Symfony\Component\HttpKernel\Exception\FlattenException;
class CustomExceptionController extends ExceptionController {
protected $translator;
public function __construct(\Twig_Environment $twig, $debug, Translator $translator) {
parent::__construct($twig, $debug);
$this->translator = $translator;
}
public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null) {
...
}
CustomExceptionController
配置中的唯一更改是使用
use Symfony\Component\Debug\Exception\FlattenException
而不是
use Symfony\Component\HttpKernel\Exception\FlattenException
(自Symfony 2.3以来已弃用)。但问题是相同的,当这变回..\HttpKernel\...
类时。
据我所知,CustomExceptionController
的配置没有其他变化。配置与Symfony docs中的配置完全相同。
知道可能出现什么问题吗?