更新到Symfony 2.8之后,Customy Exception Control不再工作

时间:2016-10-04 13:39:57

标签: php symfony exception-handling

我刚刚将Symfony 2.7页面更新为2.8。除了Symfony本身之外,还更新了许多其他软件包(例如FOSUserBundleFOSRestBundleDoctrine等)。

更新后,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中的配置完全相同。

知道可能出现什么问题吗?

0 个答案:

没有答案