在symfony2.3中,我在kernel.exception上添加了一个eventListener作为服务:当发生内核异常时触发了我的监听器但StopPropagation并没有停止事件的传播......所以内核捕获事件并且显示错误页面
在调用StopPropagation()之后,我测试了isPropagationStopped()的值:1
Vn / CommonBundle / Resources / config / services.yml:
kernel.listener.vn.MongoCursorException:
class: Vn\CommonBundle\Listener\VnExceptionListener
scope: request
tags:
- { name: kernel.event_listener, event: kernel.exception, method: onKernelException }
Vn / CommonBundle / VnExceptionListener.php:
public function onKernelException(GetResponseForExceptionEvent $event){
$exception = $event->getException();
if ($exception->getCode()=='11000') {
$attributes = (array) $event->getRequest()->attributes;
$attributes['Mongoerror']=$exception->getCode();
$event->getRequest()->attributes= new ParameterBag($attributes);
$event->stopPropagation();
}
先谢谢你的帮助!