Php 简明教程
Core PHP vs Frameworks
PHP是目前最流行的用于Web应用程序开发的服务器端编程语言,近75%的网站使用PHP(以其核心形式或可用的各种PHP框架之一)构建。为了在使用“核心PHP”或框架进行Web开发之间做出选择,我们需要了解两者之间的优缺点。
PHP is by far the most popular server-side programming language for web application development, with nearly 75% of websites using PHP either in its core form or one of the PHP frameworks available. To make a choice between using "core PHP" or frameworks for web development, we need to understand the pros and cons of both.
简单来说,用核心PHP开发Web应用程序就像通过在纸上写下每个步骤来手动解决数学问题一样。另一方面,使用框架类似于使用计算器等工具来解决问题。正如计算器一样,框架是用于快速开发应用程序的有用工具。
To give a simple analogy, developing a web application purely with core PHP is like solving a mathematical problem manually by writing down each step on the paper. On the other hand, using a framework is similar to using tools such as a calculator to solve a problem. Just as a calculator, the frameworks are useful tools for rapid application development.
Core PHP vs Frameworks – Pros and Cons
Web 框架(尤其是 PHP 框架)是一组一个或多个 PHP 库和类。它提供通用功能,从而允许开发人员更加专注于应用程序逻辑,而不是编写草稿代码。它提供可重用的软件环境,可以快速构建一个最小的工作模板应用程序。
A web framework, especially a PHP framework is a collection of one or more PHP libraries and classes. It provides a generic functionality that allows the developer to concentrate more on the application logic, rather than writing code scratch. It provides a reusable software environment that quickly builds a minimal working template application.
纯粹使用核心 PHP 开发 Web 应用程序具有自己的优点和缺点−
Developing a web application purely in core PHP has its own advantages and disadvantages −
-
It gives the developer better control and flexibility.
-
At the same time, for a larger application developed with core PHP only can become unwieldy, difficult to manage and maintain.
现在,让我们来看看使用 PHP 框架的优缺点−
Now, let’s turn to pros and cons of using PHP Frameworks −
-
A PHP framework such as Symfony, Laravel or Yii offers a more standardized approach towards web application development. With most of the routine and repetitive part handled by the framework, the developer can concentrate more on the application logic. Hence, there is lesser time wasted in debugging.
-
On the other hand, a framework is not as flexible compared to core PHP. The skeleton template of the application is readily made available by the framework, leaving the developer to customize the functionality only within the scope defined by the framework.
The MVC Architecture
大多数 Web 应用程序框架使用 MVC (模型、视图和控制器) architecture ,这通过将逻辑与样式分离,极大程度地简化了编写高质量、强大的代码。
Most of the web application frameworks employ the MVC (Model, View and Controller) architecture, which makes it a lot easier to write quality, robust code, by separating the logic from the style.
如果您希望为应用程序开发使用核心 PHP 特性,您可以在对象导向方法或模块化方法中自由选择,这取决于哪种方法更适合您。
If you wish to use the core PHP features for your application development, you are free to adopt an object oriented approach or a modular approach, whichever suits you.
Built-in Security Measures
PHP 框架提供 built-in security measures 以纳入 Web 应用程序中。
PHP frameworks offer built-in security measures to be incorporated in a web applications.
-
If you choose to develop an application with core PHP, you will have to provide the security measures explicitly.
-
Most of the frameworks however have a few external dependencies, which may leave the application rather vulnerable, as compared to a core PHP application which is a self-contained solution.
框架基于应用程序 may be a little slow 在性能方面,与核心 PHP 应用程序相比,特别是对于较小的应用程序。
A framework-based application may be a little slow when it comes to performance, as compared to core PHP application, especially for a smaller application.
Comparison: Core PHP vs Frameworks
两者的比较可以总结如下−
The comparison between the two can be summarized as follows −
-
For smaller applications, core PHP is preferrable over framework.
-
Framework offers rapid development and code reusability.
-
Frameworks are less flexible.
-
Using core PHP features, the developer has complete control.
-
For large applications, the MVC architecture is helpful.
-
Frameworks offer integrated authorization and authentication support. In a core PHP application, the security rules need to be explicitly defined.