现代的 PHP 框架介绍
今天说一下现在比较流行的 PHP 框架, 直接从 github 搜一下便可以知道大家现在正在用的框架, 大家关注的是什么
image.png
Laravel 框架
咱们首先来说一下 Laravel 框架, 它被称为为 web 艺术家创造的 PHP 框架. 这个框架这几年也是直线崛起.
Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel attempts to take the pain out of development by easing common tasks used in the majority of web projects, such as:
- Simple, fast routing engine https://laravel.com/docs/routing .
- Powerful dependency injection container https://laravel.com/docs/container .
- Multiple back-ends for https://laravel.com/docs/session and https://laravel.com/docs/cache storage.
- Expressive, intuitive database ORM https://laravel.com/docs/eloquent .
- Database agnostic schema migrations https://laravel.com/docs/migrations .
- Robust background job processing https://laravel.com/docs/queues .
- Real-time event broadcasting https://laravel.com/docs/broadcasting .
Laravel is accessible, yet powerful, providing tools needed for large, robust applications.
laravel 这个框架很有意思, 定时任务, 数据迁移, 大概你能在 web 中想到的功能这个框架都可以提供, 它的路由借鉴了 Ruby on Rails 和 Python 的 flask 框架, 但是还提供了 web 方面其它的一些功能, 你可以把它想象成 PHP 中像 Java 一样强大的 Web 中的瑞士军刀, 前提是你不考虑性能, 因为它的实现使用了大量的闭包和反射, 大概在 PHP 里严格引入设计模式的也只有这个了.
比较好的优点:
1) 遵守 PSR 规范, PHP 框架开始受束缚, 有些类必须使用 PSR 接口实现, 这一点很重要
2) 提供容器, 在容器上注入 PHP 组件驱动, 比如路由驱动, ORM 驱动, 而这些都有现成很好用的组件, composer 安装即可
3) 中间件支持, 完美的扩展 PHP 处理请求到相应的中间事件
Yii 框架
Yii 框架经历了 1.0 到 2.0 的蜕变, 由于与前代代码耦合太严重, 又向 3.0 进发了.
- Yii 2 is a modern framework designed to be a solid foundation for your PHP application.
- It is fast, secure and efficient and works right out of the box pre-configured with reasonable defaults. The framework is easy to adjust to meet your needs, because Yii has been designed to be flexible.
Yii 是一个基于组件的高性能的 PHP 的框架, 用于开发大规模 Web 应用. Yii 采用严格的 OOP 编写, 并有着完善的库引用以及全面的教程. 从 MVC,DAO/ActiveRecord,widgets,caching, 等级式 RBAC,Web 服务, 到主体化, I18N 和 L10N,Yii 提供了今日 Web 2.0 应用开发所需要的几乎一切功能. 而且这个框架的价格也并不太高. 事实上, Yii 是最有效率的 PHP 框架之一.
我自己只关注这两个框架了.
其他的框架
像 yaf,ThinkPHP 挺适合国内的开发者, 大家也可以关注.
来源: https://www.qcloud.com/developer/article/1330500