整合捆绑(相关学说2实体)在Symfony 2和耦合 [英] Integrating Bundles (Related Doctrine 2 Entities) in Symfony 2 and Coupling

查看:123
本文介绍了整合捆绑(相关学说2实体)在Symfony 2和耦合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,捆绑是分开的功能。假设我有一个 UserBundle &一个 BlogBu​​ndle 。然后我的 BlogBu​​ndle:Post 将有一个作者字段引用 UserBundle:User 。这不会破坏捆绑的目的吗?我不能交换另一个 UserBundle ?我该怎么做一个正确的方法?或者这是最好的吗?

解决方案

如果你对这些依赖关系感到不舒服(我个人同意你的看法) ,您可以在任何捆绑包之外创建您的模型。这可以像这样配置。

  doctrine_mongodb:
document_managers:
默认值:
映射:
模型:
类型:注释
dir:%kernel.root_dir%/ .. / src / MyApp / Model
前缀:MyApp\Model\
别名:模型

ORM的配置看起来会相似。


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?

解决方案

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.

这篇关于整合捆绑(相关学说2实体)在Symfony 2和耦合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆