Home >Backend Development >PHP Tutorial >Some PHP frameworks
PHP is one of the most popular programming languages in the world and is widely used in major projects. For example, Facebook uses PHP to create and maintain their internal systems; WordPress is based on PHP internally and in return provides technical support for more than 26% of the website. And now PHP has provided support for more than 82% of websites (the server-side programming language tracked by the Web Technology Surveys site).
This article will help you find the most suitable PHP framework through a comparison of the three most popular PHP frameworks: Symfony, Laravel, and Yii.
Why choose PHP framework?
Listed below are some of the benefits of developing using PHP frameworks:
PHP frameworks make development faster. For example, you don't need to write complex query operations to retrieve data from the database. PHP provides operations for Add (Create), Read (Retrieve) (retrieve data), Update (Update), and Delete (Delete).
The framework can make it easier for developers to extend the system.
Code maintenance is easier than ordinary PHP applications. Application code will be cleaner.
The MVC model ensures rapid development.
Framework better protects web applications from common security threats.
The DRY (Don’t Repeat Yourself) principle allows the least code to play the greatest role.
The benefits listed above are of great significance. Although any application can be written using native PHP, today's development requires more tools and time management skills to meet market demands.
How to choose a suitable PHP framework?
Answering the following questions can help you better choose a suitable framework:
What are the features and functions of this framework? (Does it provide what I need?)
What is the learning curve for this framework?
How scalable is this framework?
Does this framework have a positive effect on the development and maintenance of the coding team?
Does this framework provide long-term support version (LTS support)?
Does this framework have strong community support?
Overview of Symfony, Laravel and Yii
Before going into the technical details, let’s give an overview of the three:
Symfony
Symfony is a reusable PHP component that allows developers to develop scalable, high-performance applications. It has 30 components to choose from, and developers can freely experiment or work in the RAD environment.
Some well-known projects, such as Drupal and phpBB, use the Symfony framework. In fact, another popular PHP framework, Laravel, is also built on Symfony.
Laravel
"PHP framework for Web Artisans" - Laravel, as the most popular PHP framework, provides developers with an excellent community communication platform (One of the founders of Laravel is Sfiskell of Livecoding.tv).
The 5.1 version released by Laravel in May 2015 will provide a long-term support version (two years). Version 5.2 also hit the market in December 2015. There are many hosting companies that offer Laravel support as well as Laravel application hosting solutions.
Yii
Yii, created by Chinese Xue Qiang in 2008, is a safe, fast, and high-performance application/Web development framework. Yii utilizes PHP's Composer dependency manager to handle different dependencies and installations (we'll talk about that below). Lazy loading technique makes Yii the fastest PHP framework.
Another nice feature of Yii is the integration of jQuery, which allows front-end developers to get started faster. It uses scaffolding to generate code. Yii, like Symfony, uses components to make application development faster.
Comparison of Symfony, Laravel and Yii
These three frameworks are all designed to develop Web 2.0 applications, but their focuses are different. Let’s take a look at their respective features and installation:
Template engine
The template engine can reduce the burden on developers and provide more information when writing front-end code. Good functionality. The template engine provides features such as automatic HTML escaping and filtering and fills the gaps left by native PHP.
Symfony Twig Template System
Twig is a flexible, fast and safe PHP template language. The advantage of Symfony is that it uses Twig to enable developers to write clean and tidy code, and can use native PHP to implement more functions. For example, the following lengthy code implements escaping:
<?php echo $var ?> <?php echo htmlspecialchars($var, ENT_QUOTES, 'UTF-8') ?>
Twig can be implemented with the following code Same function:
{{ var }} {{ var|escape }} {{ var|e }} {# shortcut to escape a variable #}
你可以进入 Twig 主页来查看更多的功能。
Laravel Blade 模板系统
跟其他的模板系统不同,Blade 允许你在视图中使用 PHP 代码。而且,由于blade 视图文件存储在 .blade.php extension里面,所以 Blade 对你的应用性能损耗为 0。所有在视图文件里面的代码可以在处理过程中就转换成原生 PHP。
Yii 默认的模板系统
Yii 默认不使用任何第三方的模板系统,但这并不意味着它缺少模板系统的支持,模板系统的选择取决于开发团队,推荐 Twig 和 Smarty。Symfony 使用的是 Twig,所以如果你之前使用过 Symfony,你可能会想选择 Twig 作为你下一个 Yii 项目的选择。
很难定义那款才是最好的。这三个框架都利用了模板系统来更好地编写和维护前端。 Yii 的一个小优势是它没有一个预定义的模板系统。
框架的差异
每个框架的构建都是不同的。Symfony 致力于可重用组件,并提供最好的模块化。另外 Symfony 利用模块和控制器来开发 Web 应用,这可能会让一些刚入门的开发者望而却步。此外,Symfony 还是一个很好的模块化结构的例子,你可以以模块化的方式在你的项目里使用 symfony 提供的 30 个组件。
Yii采用 MVC 框架。(symfony 也支持 MVC 架构,更详细的讨论请看 blog.sznapka.pl 网站的 Is Symfony2 a MVC framework )
Symfony 可以用于快速开发复杂的项目。如果说哪个框架最适合复杂的项目的话,symfony 相比于其他框架具有十分优秀的复杂处理的能力 。Yii 也利用了组件,但和 symfony 的模块不一样。Laravel 虽然没有提供一个模块化的方法,但和其他两个框架一样好用。
如果你正在寻找一个模块化的框架的话就选择 symfony。否则,Laravel 和 Yii 都是不错的选择。
安装
这三个框架都提供了多个安装过程,如果您使用 Composer 来处理包,就发现其实所有框架都可以通过Composer 安装。
而对于 Symfony 来说,Composer 的作用尤为重要。因为使用 PHP 的 Composer 依赖项管理器是处理组件的好帮手。
当然也有其他的安装框架的方式,例如使用简单的归档方法来安装。
安装后,Yii 将提供一个 Web 应用程序和一个基本的模板帮助你的开发;Symfony 2 提供了一个开始演示应用程序;通过 Laravel 安装程序来安装和使用 Composer 来创建项目,使得 Laravel 也能够很容易安装使用。详细信息请查看 Laravel 安装指南。
发展
从公司或客户的角度来看,迅速将应用程序推向市场以满足消费者的需求并击败竞争对手是很重要的。 Symfony 由于其背后有强大的社区支撑而站稳脚跟; Laravel 正在快速成长,要被开发者完全认可仍有很长的路要走。另外,如果你还不知道任何 PHP 框架,希望尽快选择一款适合你的,Laravel 是个不错的选择,它有一个简单的学习曲线,并且有很多在线教程帮助你开始使用。Yii 将性能提升到一个新的水平,并提供代码基架,以便更快地生成和开发代码。
性能
任何应用程序的性能只有当它使用关键数据的实时应用程序时才有意义。有多少基于 Web 的应用程序依赖于高性能呢? 并不多,但是框架的性能在许多项目中可以发挥关键性的作用。
社交网络是实时事件的主要例子,我们的明星流媒体之一——jadson 就使用了 Yii2 建立移动社交网络。最快的 PHP 框架 Yii 毫无疑问是高性能应用程序编码框架的最佳选择。
Laravel 的性能是非常有争议的。它是最慢的,但这重要吗? 您可以找到很多用于加快性能的在线资源,包括使 Laravel 应用程序更快的 GitHub 指南。
数据库支持
Symfony 2 提供更好的数据库支持。您可以使用数据库数组,包括 NoSQL 和 DynamoDB。Yii 和 Laravel 也支持数据库,但是所支持的数据库比 Symfony 少。每个框架支持的数据库如表1所示。
表1
社区和资源
Community strength is an important predictor of the longevity of an open source framework. These three frameworks have their own established communities, and Symfony is relatively mature. The community is still evolving, so it is difficult to predict how it will develop in the future.
Laravel does the best job with learning materials and documentation, Symfony and Yii are not bad either:
Laravel Documentation
Symfony Documentation (3.0)
Yii Documentation
Extensibility
Frameworks are structures that can be extended or packaged to improve their functionality and scope. Laravel is the clear winner in this regard. Packalyst is a directory for Laravel packages, offering over 9000 packages. Yii and Symfony provide approximately 2800 extensions and 2830 bundles respectively. Laravel is the best framework in this regard with three times the scalability of the other two.
Symfony, Laravel and Yii Similarities
We looked at the differences between the frameworks. Now let’s look at their similarities:
1. All three frameworks are full-stack PHP frameworks and provide functionality from creating web applications from front-end code writing to back-end data retrieval.
2. These projects are all open source, their source code can be found on GitHub, everyone can easily contribute their own code:
Symfony
Laravel
Yii
3. These frameworks are well documented and get Large community support.
4. They each support ORM (Object Relational Mapping). ORMs are very fond of writing object-oriented code (OO code) for applications.
5. Using them to create Web 2.0 applications is safe and reliable.
Still can’t choose? Maybe these lists can help you narrow down your choices:
Symfony:
LTS version available,
has load function,
is currently the most stable framework,
is a component-based framework that provides a wide range of Modular,
Have a strong community and a lot of learning resources
Yii:
Comes with Ajax support
Ideal for developing real-time applications
Highly scalable
Accurate Error Handling
Good at creating Restful Web Services
Have a strong community and a large number of Learning resources
Laravel:
Conclusion:
Other resources
The above is the detailed content of Some PHP frameworks. For more information, please follow other related articles on the PHP Chinese website!