什么是 PHP 框架,什么是好的框架?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/301240/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What's a PHP framework and what's a good one?
提问by Rizwan Kassim
I am running a site about PHP Frameworks, but I can't find a exact definition for it, and I am always thinking a question, how to make out a good PHP framework? Features? Manual? Efficiency? Or something?
我正在运行一个关于 PHP 框架的网站,但我找不到它的确切定义,我一直在思考一个问题,如何构建一个好的 PHP 框架?特征?手动的?效率?或者其他的东西?
回答by Fuzzy76
Asking a programming forum what is a good framework is like asking a car forum what is a good car. The opinions vary wildly, and in 95% of cases, it really doesn't matter what you choose, as long as it's actively developed. Most of your replies will be based on religion and not subjective comparisons. :)
问编程论坛什么是好的框架就像问汽车论坛什么是好车。意见千差万别,在 95% 的情况下,你选择什么并不重要,只要它被积极开发。您的大部分回复将基于宗教而不是主观比较。:)
回答by Matt
Essentially a framework is the structure that you can choose to build your program on. It can allow you to connect to many different API's as well as determine the structure of your own application. I use the Zend Framework. It's not the easiest to learn, but certainly has everything you need for a great application. I would suggest going through the QuickStart guide on the site to get the ball rolling with this. It uses Model-View-Controller which is essential in my opinion. Once you have it configured, it makes things extremely easier!
本质上,框架是您可以选择在其上构建程序的结构。它可以让您连接到许多不同的 API 以及确定您自己的应用程序的结构。我使用 Zend 框架。它不是最容易学习的,但肯定拥有出色应用程序所需的一切。我建议您阅读网站上的 QuickStart 指南,以了解这一点。它使用模型-视图-控制器,这在我看来是必不可少的。配置好之后,事情就变得非常简单了!
Other frameworks include CodeIgniter and Symfony. Some like CodeIgniter for its smaller footprint. It's all a matter of preference. Whichever you pick be sure to use the documentation on the sites as it is essential to understanding how best to use it. Also, don't be scared to peak at the code every once in a while just to get a better understanding of how things work.
其他框架包括 CodeIgniter 和 Symfony。有些人喜欢 CodeIgniter,因为它占用的空间更小。这都是一个偏好问题。无论您选择哪种方式,请务必使用网站上的文档,因为这对于了解如何最好地使用它至关重要。此外,不要害怕时不时地查看一下代码,以便更好地了解事情是如何工作的。
回答by Rizwan Kassim
Frameworks provide scaffolding that can allow you to develop faster/more cleanly. They often provide toolsets for both the UI components and the underlying database access.
框架提供了可以让您更快/更干净地开发的脚手架。它们通常为 UI 组件和底层数据库访问提供工具集。
For (very) small projects, a framework can be overkill, but often, it's helpful to provide you with a lot of reusable code.
对于(非常)小的项目,框架可能有点过分,但通常,为您提供大量可重用的代码是有帮助的。
Some notable frameworks for PHP : Zend FrameworkCodeIgniterSymfonyCakePHPMojavi
一些值得注意的 PHP 框架: Zend Framework CodeIgniter Symfony CakePHP Mojavi
回答by Thomaschaaf
A PHP Framework in my eyes is a collection of classes which help you develop a web application.
在我看来,PHP 框架是帮助您开发 Web 应用程序的类的集合。
In my company we use the Zend Framework. I have to say that getting started with this Framework is pretty hard, but if you get how to use the API and the Reference Guide you have a great Framework. Also its interessting because they have Zend people sitting on the project so they can use those internal tricks and get some performance boosts others can't get.
在我的公司,我们使用 Zend 框架。我不得不说,开始使用这个框架是相当困难的,但如果你了解如何使用 API 和参考指南,你就会拥有一个很棒的框架。这也很有趣,因为他们有 Zend 人员参与该项目,因此他们可以使用这些内部技巧并获得其他人无法获得的一些性能提升。
What also differs ZF from others is the ability to create MVC programms with no big hassles.
ZF 与其他公司的不同之处还在于能够轻松创建 MVC 程序。
回答by Cruachan
There's a lot to be said for frameworks - and good posts here. However be aware that they are not always the best solution. Reasons you might prefer to avoid them are
关于框架有很多话要说——这里有很多好帖子。但是请注意,它们并不总是最好的解决方案。您可能更愿意避免使用它们的原因是
Because of the codebase size they tend to be slow (I've seen figures of 10 times slower simple PHP embedded page delivery quoted for Zend for example - admittedly one of the larger ones).
They can be inflexible outside the 'domain' they are intended to work with. Extending a framework to do something that is non-standard can be much more difficult than just coding from scratch.
Some sacrifice of modularity is required. The advantage of using a more simple template/control file system (such as TinyButStrong) is that each page is a distinct unit, which naturally tends to make your system easier to unit test and robust.
They tend to be vulnerable to version control issues. It's all very well and good developing your first one, but after you have a dozen or so websites developed you'll most likely find you've been using three or four release versions of the framework and you have a mish-mash of codebases to work with - and syncing everything takes time you probably won't have.
由于代码库的大小,它们往往很慢(例如,我已经看到为 Zend 引用的简单 PHP 嵌入式页面交付慢 10 倍的数字 - 诚然是较大的一个)。
在他们打算与之合作的“领域”之外,他们可能是不灵活的。扩展一个框架来做一些非标准的事情可能比从头开始编码要困难得多。
需要牺牲一些模块化。使用更简单的模板/控制文件系统(例如TinyButStrong)的优点是每个页面都是一个不同的单元,这自然会使您的系统更容易进行单元测试和健壮。
它们往往容易受到版本控制问题的影响。开发您的第一个网站一切都非常好,但是在您开发了十几个网站之后,您很可能会发现您一直在使用该框架的三个或四个发布版本,并且您有一堆代码库来使用 - 并且同步所有内容需要您可能没有的时间。
None of the above are conclusive arguments against using a framework, in many (most?) cases the advantages will score more highly, but you should not be reaching for one without first considering what your requirements are and what is the best solution for each particular problem.
以上都不是反对使用框架的决定性论据,在许多(大多数?)情况下,优势的得分会更高,但是您不应该在没有首先考虑您的要求是什么以及每个特定的最佳解决方案的情况下就达到一个问题。
回答by grigy
PHP framework is a library that makes the life of site developer easier by for example hiding some complexities of HTTP protocol or by adding some useful functions. For example the CakePHPimplements so called MVCwhich makes developer to think a level higher than HTTP. This is what I have learned so far.
PHP 框架是一个库,通过例如隐藏 HTTP 协议的一些复杂性或添加一些有用的功能,使站点开发人员的生活更轻松。比如CakePHP实现了所谓的MVC,这让开发者的思考比 HTTP 更高。这是我到目前为止所学到的。

