How to share a Symfony2 model with several projects How to share a Symfony2 model with several projects symfony symfony

How to share a Symfony2 model with several projects


What I am currently doing is the first option: create a separate bundle for your entities.That's where I store fixtures, entities, forms and entity-related tests.

A bundle does NOT need to have routing, controllers, views etc. I've actually seen a blueprint bundle, and all it does is ship blueprint-css resources with it so they can be easily reused in projects.

As for adding models to the app directory... I wouldn't like that. I see the app directory as a place where all the configuration should be. Even though you can override views under app/Resources, whenever I want to override something I create a new bundle.


I haven't used this technique myself in a real world symfony2 app - but it's a pointer as you asked for any feedback.

The service container seems to be the Smyfony2 method to make services available globally. So in your case the model access objects will be defined as services as discussed in the provided link, and then can be used from any bundle.

Now in which bundle do the service objects go? We can put them into a separate bundle as they are shared among other bundles. However, I assume the model would not be perfectly symmetrical for all the bundles, so we can put the shared model into a separate bundle, and put bundle specific entities into the bundle itself. Then injection techniques discussed in the link above can be used to provide a full model specific to each bundle.

This seems to provide maximum de-coupling.

I'm interested in any feedback on this too as it's a common design scenario.

Regards.