Just wondering if Symfony2 has an equivalent to before_filter from Rails? I want to alter the layout of my application based on the type of user that is viewing it. Thanks a lot.
EDIT: I should clarify my question. I want to alter the layout of my application based on a URL parameter. So ultimately all the before_filter equivalent has to do is make every template rendered by the controller inherit from a different base template based on that URL parameter. I should add I already have over 50 controller actions that render templates so ideally the solution should be something that is easy to enable application-wide without having to edit every controller action.
I don't know that function but you can try {% if is_granted('ROLE_XXX') %}
in twig templates or $this->get('security.context')->isGranted('ROLE_ADMIN')
in the controller
You'll find more information in http://symfony.com/doc/current/book/security.html.
Hope this helps.
Close equivalent would be creating kernel.view event listener. You can also take a look at LiipThemeBundle to change layout on the fly.