Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

An exact description of a Symfony Bundle in a complex web application

Tags:

symfony

I'm new to version 2 of the Symfony framework. I made some projects with v1 but now trying to get my head around the new version and it's features. I read over the concept of Bundles but it's purpose is not yet very clear to me.

Say you have a big web application, a CRM for example. How would the bundles look like? Would it be NewsletterBundle (for sending newsletters), ContactManagementBundle (for managing contacts), UserBundle (for editing users and their permissions).

Or would it be less cut-up like, EmailBundle (for handling the entire email traffic), CRMBundle (for putting in all your CRM code), PermissionsBundle, ApiBundle.

like image 231
tomvo Avatar asked Oct 31 '11 19:10

tomvo


1 Answers

I like to think of it like this: a bundle should represent a specific feature or set of like features for a project.

Your first example is a better use of bundles than your second example, because the purpose of each bundle is more defined. While it's possible to use one CRMBundle for everything, you wouldn't really be taking advantage of Symfony's ability to organize your code. Additionally, if you wanted to port over your Newsletter code to a new project, but not all of the CRM code, you'd have an easier time copying over a NewsletterBundle versus copying over the CRMBundle, and then pruning it.

When thinking about a Symfony2 project, sometimes you want to forget everything you know about symfony 1.x, since they take wildly different approaches to solving many problems. For example, in symfony 1 it was common to build a 'frontend' and 'backend' app for a project, and each app would obviously contain logic specific to those parts of the project. So you might have a Newsletter controller in both the frontend and backend apps. In Symfony2, you're better off using only one Newsletter bundle, but with two controllers (perhaps named 'frontend' and 'backend'). Again, an immediate benefit to this is how reusable your code becomes.

like image 192
Steven Mercatante Avatar answered Nov 09 '22 16:11

Steven Mercatante