Symfony2捆绑软件:我使用的对吗? [英] Symfony2 bundles: am I using them right?

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

问题描述

我有一个用 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 -包括每个层(控制器服务域逻辑和与该论坛有关的 persistence ).

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.

推荐答案

关于如何使用捆绑包构建应用程序没有硬性规定,但这是我在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.

使用一个特定于应用程序的捆绑包.首先,我

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.

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

You can organize your code neatly using subnamespaces. For example, the backend controllers would go to the AppBundle\Controller\Backend subnamespace.

请注意,我在说的是一个 app专用包-这种东西对于具体的app来说是唯一的,在其他地方重复使用是没有意义的.您仍然可以为可重复使用的物料开发单独的捆绑包,并将其放入供应商的基础架构中.

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捆绑软件:我使用的对吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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