Search code examples
symfonybefore-filter

Symfony some logic before controller


I'm a newbie to Symfony and I'm trying to switch my current project over to it.

For most of my controllers I need to do some multiple checks BEFORE executing the controller. Then if certain conditions are met for the check, forward them and show a different view, otherwise continue on to what they requested.

For example I have a group of controllers which should only be executed if the user is in a crew otherwise it loads a view saying "you're not in a crew".

This is very straight forward in procedural code, yet in OOP seems to get more complex, and now within a framework I seem to find myself even more limited.

How does one add logic before the controller is executed?


Solution

  • You want to set up before-filter logic. It's not something simple enough to write into a post here, but here's a good tutorial on doing so. If you have a specific issue with it, post here and I'll try to update with help: http://symfony.com/doc/2.0/cookbook/event_dispatcher/before_after_filters.html