Symfony2中的捆绑包应该代表什么 [英] What should a bundle in Symfony2 represent

查看:80
本文介绍了Symfony2中的捆绑包应该代表什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这对您来说可能是显而易见的事情,但是-即使在阅读了许多手册和博客之后-我仍然不确定Symfony2中的捆绑包应该在网页中确切显示什么.很难从简单的演示应用程序中猜到它.

This might be an obvious thing to you but - even after reading through a lot of manuals and blogs - I'm still not sure what exactly should a bundle in Symfony2 represent in a webpage. And it's hard to guess it from the simple demo applications.

例如:我有一个站点,该站点分为两个部分(一个站点只是一个像example.com这样的第二级域,另一个站点是dom2.example.com).这两个部分各有其各自的部分-有时相同(例如新闻),有时不同.

For example: I have a site which is divided into two parts (one is just a 2nd level domain like example.com and another is dom2.example.com). Each of these two parts has some sections of it's own - sometimes the same (like news) sometimes different.

在symfony2中此的正确表示是什么?我应该有

What would the correct representation of this in symfony2? Should I have

  • 捆绑MySite\site1MySite\site2并通过不同的控制器执行不同的部分,或者
  • 捆绑包Site1\NewsSite2\News,或
  • 捆绑包MySite\Site1NewsMySite\Site2News
  • a MySite\site1 and MySite\site2 bundle and do the different sections via different controllers, or
  • bundles Site1\News and Site2\News, or
  • bundles MySite\Site1News and MySite\Site2News etc.

...或者我对此完全理解吗?

...or am I getting all wrong at this?

推荐答案

我也是Symfony的新手,将感兴趣地关注该问题的结果,但是对于我的价值,我的看法是:

I am also new to Symfony and will follow the results of this question with interest, but for what it's worth, my take on it is:

捆绑包就是这样:一组文件,资产,PHP类和方法,测试等.分组的逻辑可以是您喜欢的任何东西.在某些情况下,很明显,分组是什么,为什么要进行分组-例如,如果我为Symfony2写了一个博客系统并想发布它,我会将其打包.这就是文档中使用最多的示例.

A bundle is just that: a group of files, assets, PHP classes and methods, tests, etc. The logic of the grouping can be anything you like. In some cases, it's really obvious what the grouping is and why it's been done -- for instance, if I wrote a blog system for Symfony2 and wanted to release it, I'd make it into a bundle. That's the sort of example used most in the documentation.

但是,您还可以将捆绑软件用于任何要发布的功能,作为一项小功能.例如,说此捆绑包,它将为您的所有控制器创建默认路由.它不是像博客或论坛那样的完全开发的插件/功能,但是我可以很容易地将其导入项目中,但与其他所有代码完全分开,这是一个捆绑包.

But you'd also use bundles for anything you wanted to release as one little feature. Say for instance, this bundle which creates default routes for all your controllers. It's not a fully developed plugin/feature like a blog or forum, but it's a bit of code that I can easily import into my project, it stays totally separate from everything else, it's a bundle.

最后,您还可以在项目内部使用捆绑包,绝不使用任何对您有意义的方式.

Finally, you'd also use bundles internally to your project, in absolutely any way which makes sense to you.

我对您的具体情况有看法

My take on your specific situation:

快速简便:

  • MySite\MyCode-完成工作,也许您没有任何逻辑方法来分解要编写的代码.
  • MySite\MyCode -- gets the job done, and maybe you don't have any logical way to break up the code you're going to write.

如果这两个站点之间还有其他一些独特的功能,并且您想将它们分开以进行清楚说明:

If there's some more unique features between the two sites and you want to separate them out for clarity:

  • MySite\SharedFeatures
  • MySite\Site1Features
  • MySite\Site2Features
  • MySite\SharedFeatures
  • MySite\Site1Features
  • MySite\Site2Features

如果您真的很喜欢所有内容,或者您​​有一个复杂的项目,也许:

If you really like everything in its place, or if you have a complex project, maybe:

  • MySite\MySiteMain(共享的功能和所有其他杂物,不值得单独购买)
  • MySite\News
  • MySite\Site1FeatureSomethingOrOther
  • MySite\Site2FeatureSomethingOrOther
  • MySite\MySiteMain (shared features and catch-all miscellany that doesn't deserve its own bundle)
  • MySite\News
  • MySite\Site1FeatureSomethingOrOther
  • MySite\Site2FeatureSomethingOrOther

我绝对认为您希望坚持使用逻辑代码组-因此,我认为您的示例将Site1 \ News和Site2 \ News捆绑在一起"和"MySite \ Site1News和MySite \ Site2News"捆绑在一起并不是最好的选择. Site1和Site2是实现,因此为每个站点的新闻页面创建单独的捆绑包似乎对我适得其反;您想要制作一个新闻组件并构建它以两种不同方式使用.

I definitely think you want to stick to logical groups of code -- so I think your example "bundles Site1\News and Site2\News" and "MySite\Site1News and MySite\Site2News" wouldn't be the best way to go. Site1 and Site2 are implementations, so making a separate bundle for each site's news page would seem to be counterproductive to me; you'd want to make one news component and build it to be used in two different ways.

对于两个域的问题,您可以将两个域都指向相同的代码,然后在代码中测试所请求的域,或者可以签出相同代码的两个副本并更改配置文件稍有一点(这不一定违反 DRY 的想法,因为您仍然可以编辑代码放在一个地方,然后更新两个副本.)

As for your two-domains question, you can either point both domains at the same code, and test within your code for what domain is being requested, or you can check out two copies of the same code and change the configuration files slightly (this doesn't necessarily violate the idea of DRY because you'd still edit the code in one place, then update both copies.)

这篇关于Symfony2中的捆绑包应该代表什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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