复杂 Web 应用程序中 Symfony Bundle 的准确描述 [英] An exact description of a Symfony Bundle in a complex web application

查看:23
本文介绍了复杂 Web 应用程序中 Symfony Bundle 的准确描述的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Symfony 框架第 2 版的新手.我用 v1 做了一些项目,但现在试图了解新版本及其功能.我阅读了 Bundles 的概念,但它的目的对我来说还不是很清楚.

I'm new to version 2 of the Symfony framework. I made some projects with v1 but now trying to get my head around the new version and it's features. I read over the concept of Bundles but it's purpose is not yet very clear to me.

假设您有一个大型网络应用程序,例如 CRM.捆绑包会是什么样子?是 NewsletterBundle(用于发送时事通讯)、ContactManagementBundle(用于管理联系人)、UserBundle(用于编辑用户及其权限).

Say you have a big web application, a CRM for example. How would the bundles look like? Would it be NewsletterBundle (for sending newsletters), ContactManagementBundle (for managing contacts), UserBundle (for editing users and their permissions).

或者,它会不会像 EmailBundle(用于处理整个电子邮件流量)、CRMBundle(用于放入您的所有 CRM 代码)、PermissionsBundle、ApiBundle 那样分割.

Or would it be less cut-up like, EmailBundle (for handling the entire email traffic), CRMBundle (for putting in all your CRM code), PermissionsBundle, ApiBundle.

推荐答案

我喜欢这样想:一个包应该代表项目的一个特定功能或一组相似的功能.

I like to think of it like this: a bundle should represent a specific feature or set of like features for a project.

您的第一个示例比第二个示例更好地使用了 bundle,因为每个 bundle 的用途都更加明确.虽然可以为所有事情使用一个 CRMBundle,但您不会真正利用 Symfony 组织代码的能力.此外,如果您想将 Newsletter 代码移植到一个新项目,但不是全部 CRM 代码,与复制 CRMBundle 相比,复制 NewsletterBundle 会更容易,然后修剪它.

Your first example is a better use of bundles than your second example, because the purpose of each bundle is more defined. While it's possible to use one CRMBundle for everything, you wouldn't really be taking advantage of Symfony's ability to organize your code. Additionally, if you wanted to port over your Newsletter code to a new project, but not all of the CRM code, you'd have an easier time copying over a NewsletterBundle versus copying over the CRMBundle, and then pruning it.

在考虑 Symfony2 项目时,有时您想忘记您对 symfony 1.x 的了解,因为它们采用截然不同的方法来解决许多问题.例如,在 symfony 1 中,为一个项目构建前端"和后端"应用程序是很常见的,每个应用程序显然都包含特定于项目这些部分的逻辑.因此,您可能在前端和后端应用程序中都有一个 Newsletter 控制器.在 Symfony2 中,最好只使用一个 Newsletter 包,但使用两个控制器(可能名为前端"和后端").同样,这样做的直接好处是您的代码变得可重用.

When thinking about a Symfony2 project, sometimes you want to forget everything you know about symfony 1.x, since they take wildly different approaches to solving many problems. For example, in symfony 1 it was common to build a 'frontend' and 'backend' app for a project, and each app would obviously contain logic specific to those parts of the project. So you might have a Newsletter controller in both the frontend and backend apps. In Symfony2, you're better off using only one Newsletter bundle, but with two controllers (perhaps named 'frontend' and 'backend'). Again, an immediate benefit to this is how reusable your code becomes.

这篇关于复杂 Web 应用程序中 Symfony Bundle 的准确描述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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