Question

I am just starting in Symfony 2 and couldn't find a preprocessor method like Zend's init() for controller classes.

This is useful, because one may want to have some global code executed before any action method inside a controller, as for using $this for Model instanciated in all action methods.

Hope I made myself clear.

Thanks in Advance!

Was it helpful?

Solution

Symfony uses Events for that.

In this case you would listen to KernelEvents::CONTROLLER, or make a service listen to that event by tagging it:

<tag name="kernel.event_listener" event="kernel.controller" method="onKernelController" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top