Symfony 2:实体位置 [英] Symfony 2 : Location of Entities

查看:75
本文介绍了Symfony 2:实体位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Symfony 2上还很陌生,我想知道一些事情:

I'm pretty new at Symfony 2 and I was wondering something :

假设我的项目中有2个捆绑包。我想同时使用两个数据库中从数据库生成的实体。

Let's assume I have 2 bundles in my projects. I want to use entities generated from my database in both bundles.

我应该在哪里生成实体? (对我来说,最好的方法是在捆绑包之外,但我不知道怎么做)

Where am I suppose to generate the entities ? (To me the best way would be outside the bundles but I can't find out how to do that)

感谢您的帮助。

推荐答案

我认为有两种解决方案,您必须考虑应用程序的设计。

I think there is two solutions, you have to think of the design of your application.

确定要两捆吗?如果两者之间的联系如此紧密,那么为什么不选择只捆绑一个呢?在这种情况下,您只需要将实体生成到该捆绑包中即可。

Are you sure you need two bundles ? If the link is so strong between the two, why didn't you choose to make only one bundle ? In this case, you'll just have to generate the entities into this bundle.

其他情况:您实际上需要两个捆绑包,但是在此特定应用程序中,您需要两者之间的联系。在这种情况下,我认为您应该在它所属的捆绑软件中生成实体,如果需要,可以在另一个捆绑软件中使用它们(感谢使用MyApp\MyBundle\Entities\。 ..; )。为了能够在其他项目中重用捆绑软件,在使用Symfony时必须考虑通用代码。 ;)

Other case : you effectively need two bundles, but in this specific application you need to make a link between the two. In this case, I think you should generate the entities in the bundle where it belongs, and if you need so you can use them in another bundle (thank to use MyApp\MyBundle\Entities\...;). You have to think in terms of generic code when using Symfony, in order to be able to reuse your bundles in other projects. ;)

这篇关于Symfony 2:实体位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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