Onita
Onita

Reputation: 154

Symfony2 - Execute a function before calling the action and all bundles

I want to execute a function when a road is called it in any controller but before the call to action.

The goal is that the code is invisible in the controller and do it the best walkthrough possible.

Upvotes: 2

Views: 1417

Answers (1)

unairoldan
unairoldan

Reputation: 2863

Here you have the solution: https://matt.drollette.com/2012/06/calling-a-method-before-every-controller-action-in-symfony2/

In short, you have to intercept the call to a Controller using a Kernel event, and then execute your code inside the listener. You can "select" which controllers use this behavior extending a particular Interface.

Upvotes: 2

Related Questions