Symfony2 : onKernelResponse called twice as MASTER_REQUEST

孤街浪徒 提交于 2019-12-05 07:25:08

Finally found the origin of the problem : the debug toolbar !

It actually sends an ajax request, meaning another MASTER_REQUEST..

My solution is to filter on Controller, with a white/black list of controller's names.

UPDATE:

Here is the code I'm using (so you can easily exclude some other controllers if needed).

public function __construct()
{
    $this->classesExcluded = array("Symfony\Bundle\WebProfilerBundle\Controller\ProfilerController");
}


public function onKernelController(FilterControllerEvent $event)
{
    $controller = $event->getController();

    if (!is_array($controller) || HttpKernelInterface::MASTER_REQUEST != $event->getRequestType() || in_array(get_class($controller[0]), $this->classesExcluded)) {
        return;
    }
  // ...
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!