简体   繁体   English

Symfony2捆绑系统

[英]Symfony2 Bundle System

I'm just working through the Symfony2 Bible and I'm a little stuck on the bundle system. 我只是在研究Symfony2圣经,而且我有点卡在捆绑系统上。 It is a great feature but I'm not quite sure how to split my flat PHP application into bundles. 这是一个很棒的功能,但我不太确定如何将我的平面PHP应用程序拆分成捆绑包。 It's my first time splitting my PHP code into a full featured MVC framework. 这是我第一次将PHP代码拆分为功能齐全的MVC框架。

I'm working on a few online games (based on PHP) but how would I define the bundles ? 我正在开发一些在线游戏(基于PHP),但我如何定义捆绑? Is it like one single onlinegame1 bundle with all the controllers and functions - Or like a login bundle, a register bundle, a war bundle - summarized one bundle for every single PHP file I got ? 它是否像一个包含所有控制器和函数的单一onlinegame1包 - 或者像登录包,寄存器包,war包 - 为我获得的每个PHP文件汇总了一个包?

I want to start clean and correct but I'm not quite sure if I understand that feature. 我想开始干净和正确,但我不太确定我是否理解这个功能。

You could think of bundle as an independent reusable component - in most of the cases at least. 您可以将bundle视为一个独立的可重用组件 - 至少在大多数情况下。

Let's imagine a personal blog website. 让我们想象一下个人博客网站。 I'd split it into ArticleBundle , UserBundle , CommentBundle and finally MainBundle which would stick all these other bundles together, creating your website. 我将它拆分为ArticleBundleUserBundleCommentBundle ,最后是MainBundle ,它将所有这些其他捆绑包粘在一起,创建您的网站。 The main point is that you can take for example ArticleBundle and reuse it easily on other project without it being tied to any other bundle. 重点是,您可以采用例如ArticleBundle,并在其他项目上轻松地重复使用它,而不会将其绑定到任何其他捆绑包。

From Symfony2 book : 来自Symfony2的书

A bundle is similar to a plugin in other software, but even better. 捆绑包类似于其他软件中的插件,但更好。 The key difference is that everything is a bundle in Symfony2, including both the core framework functionality and the code written for your application. 关键的区别在于Symfony2中的所有内容都是一个包,包括核心框架功能和为您的应用程序编写的代码。 Bundles are first-class citizens in Symfony2. 捆绑包是Symfony2中的一等公民。 This gives you the flexibility to use pre-built features packaged in third-party bundles or to distribute your own bundles. 这使您可以灵活地使用打包在第三方软件包中的预构建功能,或者分发您自己的软件包。 It makes it easy to pick and choose which features to enable in your application and to optimize them the way you want. 它使您可以轻松选择要在应用程序中启用的功能,并以您希望的方式对其进行优化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM