Search code examples
symfonybundlecode-organization

Symfony2 bundle management


I was drawn to Symfony 2 for many reasons but especially I liked the idea of Bundles to organise and modularise code.

However, I'm not sure as to best practise regarding how specific a single bundle should be.

For example, if I wanted to build a calendar app then I would have to deal with users calendars and also the events relating to those calendars.

Would it be considered best practise to have a calendars bundle and a seperate events bundle or should I have one bundle that has an events controller and a calendar controller?

Of course someone might suggest a different approach again!


Solution

  • I think the answer depends on a few different things. When I build an app with Symfony2 I usually like my bundles to by somewhat small. My initial opinion for your question is that the events should be in the same bundle as the calendar. However I am basing this answer on a few assumptions.

    I am assuming, for example, that the events 100% depend on calendars. Usually if an entity can live completely independent of another I like to have them in separate bundles. Can events be created or managed without ever touching/needing the calendar? If the events will have their own page, their own management portal and are simply attached to a calendar (for example, when someone subscribes to an event), then I would have a separate bundle.

    Of course these are my opinions...I think is kind of a grey area.

    Hope this helps.