How to share a Symfony2 model with several projects

后端 未结 2 1655
一生所求
一生所求 2021-02-07 11:53

We are creating a SaaS that monitors certain assets. This means it takes in data, saves it, and displays it in a webinterface.

For this, we have a few components that we

相关标签:
2条回答
  • 2021-02-07 12:46

    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.

    0 讨论(0)
  • 2021-02-07 12:47

    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.

    0 讨论(0)
提交回复
热议问题