Symfony2 bundles:我用对了吗? [英] Symfony2 bundles: am I using them right?

查看:28
本文介绍了Symfony2 bundles:我用对了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在 Symfony2 中开发的应用程序.现在它的结构如下:

I have an application which is developed in Symfony2. Now the structure for it is as follows:

  • FrontBundle - 包括与应用程序的视图和 UI 相关的所有内容.
  • PersistanceBundle - 包括与应用程序持久层相关的所有内容.
  • DomainBundle - 包括与应用程序实体和服务相关的所有内容.
  • FrontBundle - includes everything related to the application's view and UI.
  • PersistanceBundle - includes everything related to the persistence layer of the application.
  • DomainBundle - includes everything related to the entities of the application and the services.

这个结构好吗?或者像论坛功能一样使用捆绑包 - ForumBundle - 它包括每一层(控制器服务域逻辑持久性)与论坛相关.

Is this structure ok? Or bundles are used like forum feature - ForumBundle - which includes every layer (controllers, services, domain logic and persistence) related to the forum.

推荐答案

关于如何使用 bundle 构建应用程序没有硬性规定,但这是我在 Symfony2 上开发近一年后得出的结论.

There are no hard and fast rules on how to structure your app using bundles, but here's what I came to after developing on Symfony2 for close to a year.

使用一个特定于应用的捆绑包.起初,我开始使用多个包,如CommonBundleUserBundleMainBundleBlogBu​​ndleContactBundle 等.最后证明这不是那么方便,所以我只切换到一个特定于应用程序的包 — AppBundle.

Use one app specific bundle. At first, I started with multiple bundles like CommonBundle, UserBundle, MainBundle, BlogBundle, ContactBundle, etc. That proved to be not so convenient in the end, so I switched to just one app specific bundle — AppBundle.

您可以使用子命名空间整齐地组织代码.例如,后端控制器将转到 AppBundleControllerBackend 子命名空间.

You can organize your code neatly using subnamespaces. For example, the backend controllers would go to the AppBundleControllerBackend subnamespace.

请注意,我说的是一个特定于应用程序的捆绑包 — 特定于具体应用程序的东西,在其他地方重用没有意义.您仍然可以为可重复使用的东西开发单独的包,并将它们放入供应商的基础架构中.

Note that I'm talking about one app specific bundle — that stuff that's unique to the concrete app and won't make sense to reuse elsewhere. You can still develop separate bundles for reusable stuff and put them into the vendors infrastructure.

将非 Symfony 特定的内容保留在捆绑包之外. 无需为模型和 服务层 类,如果它们不是特定于 Symfony2 的.请参阅这个问题和我的回答以了解更多详情.

Keep non Symfony specific stuff out of bundles. There is no need to have a bundle for the model and the Service Layer classes in a bundle if they are not Symfony2 specific. See this question and my answer for further details.

这篇关于Symfony2 bundles:我用对了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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