How to disable Listener for certain routes in symfony2? How to disable Listener for certain routes in symfony2? symfony symfony

How to disable Listener for certain routes in symfony2?


One approach is to mark the routes to be ignored in their definitions. Something like:

cerad_game__project__game_report__update:  pattern:  /project/{_project}/game-report/{_game}/update  defaults:    _ignore: true    _model:      cerad_game__project__game_report__update__model_factory    _form:       cerad_game__project__game_report__update__form_factory    _controller: cerad_game__project__game_report__update__controller:action    _template: '@CeradGame/Project/GameReport/Update/GameReportUpdateTwigPage.html.twig'

A simple $request->has('_ignore') will do the trick.


You can register your own event listener that has a higher priority than every listener that should optionally be skipped. In this listener you can perform whatever test you need to make to detect if other listeners should be skipped. If that's the case just call the stopPropagation() method of the Event instance you get passed.

But you need to be careful which priority you use to register your listener as Symfony itself performs a lot of things through event listeners and skipping them might lead to unexpected behaviour. However, you can see the list of registered core event listeners in the documentation.