As I understand, Bundles is to separate functionality. Suppose I have a UserBundle
& a BlogBundle
. Then my BlogBundle:Post
will have an author
field that references UserBundle:User
. Doesn't that defeats the purpose of Bundles? I cant swap another UserBundle
in? How can I do it a proper way? Or is this the best it can go?
相关问题
- Symfony2 Set Controller in the kernelControllerEve
- Webpack Encore: cannot import local dependencies
- Render custom attribute KNP Menu
- Problems with cap deploy a symfony2 project, can
- Allow CORS on symfony 4
相关文章
- Symfony : Doctrine data fixture : how to handle la
- Symfony is linked to the wrong PHP version
- Symfony2: check whether session exists or not
- Is there a way to modify the entity mapping config
- symfony2 form choice and mongodb
- Get random records with Doctrine
- Symfony 3.1 and OneUpUploaderBundle + Blueimp = Up
- Doctrine not finding data on Google App Engine?
Bundles are meant to separate functionality as much as possible, but that doesn't mean that some won't have dependencies on others.
I think it's interesting that even some of the Symfony2 components, which are supposed to be stand-alone libraries, have dependencies. For example, the
HttpKernel
class depends on classes from theHttpFoundation
andEventDispatcher
components.In your example, if you needed to swap in another
UserBundle
, you'd have to take the necessary steps to ensure yourBlogBundle
's dependency is still fulfilled. This may mean you need to refactor.So, the purpose of bundles isn't defeated because one references the other. Bundles are still advantageous to use even if they're not always 100% uncoupled.
Well, in context of another application one might not want to bind a given blog post to a person/user, rather than a group. To keep your code portable to its maximum I think you should abstract the scenario a bit. Relations would be unacceptable. Owner identity, on the other hand, is.
So imagine that a given blog post has an owner. In the context if a different application with its own bundles, an owner identity might be a group, a user, an outside source, etc.
Imho you should use only id of the "one" who has wrote the article, not bounding your implementation implying that this would be a "person" on the local database.
If you are uncomfortable with those dependencies between bundles (I personally agree with you), you can create your model outside of any bundle. This can be configured like so…
Configuration for the ORM would look similar.