This week we are blogging the results of our evaluation of the popular PHP framework called Yii2. This is the second part of our PHP Frameworks Blog series that started with our initial post and our post on the popular PHP framework Laravel. The Yii framework, started by founder Qiang Xue in 2008, was known for its performance metrics and has had a very solid following with strong community support. Yii underwent a complete rewrite in 2014, and the 2.0 release (beta) has been positively received. It offers what you would expect from a well-designed framework, such as: better REST API support, use of advanced php5 features, and better namespacing, among other things. Our evaluation is based on criteria we established in our overview blog. Read on…
Category 1: Core Framework Design
Because Yii2 was completely rewritten, the developers were able to take lessons learned from Yii to create a light weight framework that builds on industry recommended design principles and takes advantage of the latest language features for PHP 5.4.
- MVC support
As with most PHP frameworks, Yii2 implements the MVC architectural pattern and promotes code organization based on that pattern. It also has a scaffolding capability called Gii which simplifies the creation of the code.
- Thin controller
The thin controller and fat model is the recommended model and Yii2 certainly supports this.
- Exception handling at the framework level
The framework includes a built in error handler which makes it easy to debug, especially with access to the stack trace and source code. It can also handle different error formats.
- Inheritable configuration with respect to environments and installation across servers
The ‘environments’ directory is meant to solve the issue of messy installation issues. The configuration files can override each other to avoid duplication.
- Overhead required to create basic module configuration
For simple scenarios, this can be done using their nifty code generator, along with models, CRUD, controllers, extensions by default. http://www.yiiframework.com/doc-2.0/guide-tool-gii.html
- PHP 5.5+ support
The minimum Yii2 requirement is 5.4. For this evaluation, we tested with 5.6.
- Event management framework
Events management is supported in Yii2. You can also add event handlers to all instances of a class at once which can be a convenient feature.
- Dependency injection support
Yii2 provides dependency injection support (yii\di\Container).
- Ease of bootstrapping and integrating with PHPUnit
Yii2 integrates with PHPUnit easily and it can also use Codeception.
- UI templating support
Yii2 uses layouts, views and can support other rendering engines, such as Twig or Smarty available as extensions.
- Command Line interface (CLI) to execute applications
Yii2 also has a cli tool to facilitate the minification of frontend assets.
- Support for manipulation of various data formats like JSON and XML
Yii2 supports both json and xml response formats.
- Useful debugging tools.
There are tools such as logger support with customizable log levels, DB call instrumentation and request parameter logging.
Default debug toolbar and debugger shows logs, request params, header info, db queries, etc.
Category 2. Performance, Scalability and Redundancy.
One of Yii’s original selling points was the performance capabilities. Yii2 continues to have great performance out of the box with lazy loading in addition to supporting various caching techniques and the ability to profile performance with its debugger.
- Support for application caching
Yii2 supports multiple caches using cache components. It makes it easy to switch out the underlying cache without making any code changes.
- Special features or capabilities focused on performance
The default debug toolbar and debugger shows metrics that allow you to tweak the performance.
- Proven adoption on large projects
At the time of the evaluation, there were many small to midsized sites we’ve found such as vice.com, realself.com, and stay.com to name a few.
Category 3. Security
Yii2 comes with security component that help with creating secure applications.
- Modules for security such as authentication and authorization, and granular access controls
Class yii\base\Security supports Encryption/decryption, key derivation using standard algorithms, data tampering prevention, and password validation.
- Frequent security patching
So far in 2015, there appears to be a point release every 2 months or so, which contain security fixes.
Category 4. Instrumentation and Troubleshooting Support
Yii2 has a great debug toolbar that helps not only with debugging but database and performance profiling as well.
- Instrumentation metrics or accessibility at the method level
This is supported by the debug toolbar and debugger.
- Instrumentation metrics or accessibility at the SQL level
This is supported by the debug toolbar and debugger.
Category 5. Database and Object-Relational-Mapping (ORM) Support
Yii2 Active Record is widely adopted and simplifies database interaction.
Support for models that interact with relational databases used at the client, specifically MySQL and Oracle, and possibly MariaDB in the future.
Yii2 supports DB migration, DAO, query builder, and Active Record. It supports MySQL, MariaDB, SQLite, PostgreSQL, CUBRID: version 9.3 or higher, Oracle, MSSQL: version 2008 or higher.
Support for fine tuning of the SQL used in the ORM
ORM supports subqueries as well.
Support for interaction with NoSQL databases like MongoDB
This is supported by third party extensions. Yii and MongoDB
Category 6. Community Support
Yii2 has great documentation and a large user base that provides support content that is easily accessible.
- Active maintenance and periodic releases
The release cycle is about every 4-5 months with 300+ committers on github.
- Large developer community, support and discussion forums
The forums and chat rooms are very active. http://www.yiiframework.com/community/
- Ability to run on a wide variety of Linux and Unix platforms such as RedHat/CentOS, Ubuntu, and MacOS
Yii2 can run on all supported operating systems.
- Well documented – up to date with current release
The definitive guide to Yii2 is very good. Many tutorials we found were based on v1 but as the Yii2 community continues to grow, we’ll see more and more Yii2 based tutorials.
In conclusion, the Yii2 framework’s ease of installation, configuration management, extensibility and debug/testing features allow for quick development time which leads to fast application delivery. The active community and up-to-date documentation proved to be a great resource in getting a quick prototype up and running for our needs.
Have you used Yii2? We welcome hearing about your experiences with it.