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?

- 84,767
- 185
- 495
- 805
-
The thing that I find irritating is: if I make a bundle available to the community, and it has dependencies, the downstream dev has to sort out the installation of those deps. I would like a deps system where I specify deps for my bundle, and `bin/vendors install` takes care of it w/o the downstream dev having to fumble around with 3rd party bundles. This and the lack of built-in admin generator are my main points of contention with s2 (as a veteran s1 user) – yitznewton Dec 26 '11 at 16:13
-
3@yitznewton, [Composer](https://github.com/composer/composer) is being developed to solve this problem. – Elnur Abdurrakhimov Dec 26 '11 at 16:18
-
@elnur when are we going to run out of musical project names? TY :) – yitznewton Dec 26 '11 at 17:17
3 Answers
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…
doctrine_mongodb:
document_managers:
default:
mappings:
model:
type: annotation
dir: %kernel.root_dir%/../src/MyApp/Model
prefix: MyApp\Model\
alias: Model
Configuration for the ORM would look similar.

- 8,945
- 1
- 37
- 25
-
I've never used this method, and I'm curious how you would reference a repository, since you'd normally write `SomeBundle:SomeEntity`. Would prefix take the place of bundle? ex `MyApp:Model` (based on your example config) ? – Steven Mercatante Dec 26 '11 at 19:18
-
1But suppose I am developing a `UserBundle` where I can use it for multiple projects, won't I need to distribute the models separately? Also it seems to be like this is just another bundle, just not "officially" one – JM at Work Dec 27 '11 at 02:44
-
1@Arms: you would reference the model using the configured alias (i.e. `Model:User`) – Kris Wallsmith Dec 27 '11 at 23:27
-
@JMatWork: in that case you would want to put the models in the bundle – Kris Wallsmith Dec 27 '11 at 23:28
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 the HttpFoundation
and EventDispatcher
components.
In your example, if you needed to swap in another UserBundle
, you'd have to take the necessary steps to ensure your BlogBundle
'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.

- 24,757
- 9
- 65
- 109
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.

- 4,724
- 1
- 33
- 41