Symfony2:如何将现有数据库导入到不同的包中
我在这里看到了很多帖子,这些帖子描述了有关将应用程序组织在其包含的实体上的捆绑包中的关注点分离。但他们都没有指出这些实体通过不同的捆绑包相关的这一点。
由于我已经有一个现有数据库,其中包含帖子、评论、标签、用户、角色等表,我想将此定义导入到我的新 symfony2 项目中。 我的问题是,我希望将其放在不同的包中,例如 BlogBundle、UserBundle、StaticBundle...,但我不知道如何将相应的实体导入到正确的包中。 进一步的问题是用户实体在帖子和评论实体中被引用,所以我应该怎么做。当我将帖子、评论、标签导入 BlogBundle 时,用户实体尚不存在。
谁能指导我如何继续该过程?
I've seen a lot of posts here which describes the separation of concerns regarding organizing your app in bundles which work on their containing entities. But none of them states the point that these entities are related through different bundles.
As I already have an existing database which contains tables for posts, comments, tags, users, roles and some more I want to import this definition into my new symfony2 project.
My problem is that I would like to have that in different bundles like BlogBundle, UserBundle, StaticBundle, ..., but I do not know how to import the respective entities into the right bundle.
Further problem is that the user entity is referenced inside the post and comment entity so how should I do that. When I import the post, comment, tag into the BlogBundle, the user entity does not exist yet.
Can anyone guide me with a hint on how to go on with that process?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实体在捆绑包之间共享(当然)。
如果你想做一个博客,你可以创建一个 UserBundle (它可以覆盖很棒的 FOSUserBundle)和 BlogBundle。
UserBundle 将包含您的 User 实体,BlogBundle 将包含您的 Post 和 Comment 实体。
现在是一个代码示例:
在您的 UserBundle 中:
在您的 BlogBundle 中:
因此,由于这样的注释,您引用了另一个包中的实体:
无论如何,您应该真正阅读 Symfony2 文档,它可能会帮助你理解一切。
Entities are shared between bundles (of course).
If you want to do a blog, you can create a UserBundle (which could override the awesome FOSUserBundle for example), and a BlogBundle.
UserBundle will contain your User entity, BlogBundle will contain your Post and Comment entities.
Now an example of code:
In your UserBundle:
In your BlogBundle:
So you reference an entity in another bundle thanks to such annotations:
Anyway, you should really read the Symfony2 documentation, it might help you understand everything.