Posted by Fred Wu
It was over a year ago that I wrote the article that compares CodeIgniter and Kohana. Since then both CodeIgniter and Kohana have seen major progress with the release of CodeIgniter 1.7.0 and Kohana 2.3.
In December 2008, a new PHP framework called Yii has been released to the public with a stable 1.0. There were a lot of new PHP framework released in 2008, but Yii was one of the more recognised ones because:
- The author, Qiang Xue, is the author of the well established PRADO framework.
- It is a simple to use, well organised, PHP 5 only MVC framework.
- It claims to have astonishing performance.
Before I start this round of comparison, let me briefly list my experience with these frameworks, so you may interpret this article with your own judgement.
CodeIgniter: I started using CodeIgniter since its version 1.2.x from a few years ago. During the past few years I have worked on projects mainly using version 1.5.x and 1.6.x. I have now stopped using CodeIgniter in favour of using other PHP 5 only frameworks.
Kohana: I first started using Kohana when it was called BlueFlame back when it was first forked out of CodeIgniter. Since then I have lurked and participated in the Kohana community. All of my recent projects are done in Kohana.
Let’s see how they compare with each other.
Same notes as before: Grading scale: Limited < Fair < Good < Excellent. If a feature is not available in the distributed package, but is available via 3rd party libraries, I will state that in the comparison. If a feature is available both in the distributed package and via 3rd party libraries, only the official one will get assessed.
Software releases used for this comparison are:
CI uses a modified, generally regarded as more restrict, BSD/Apache-style license.
Kohana uses a new BSD license.
Yii uses a new BSD license.
PHP >= 4.3.2 (including all versions of PHP 5)
At first glance, it seems that CI has the edge because it supports both PHP 4 and PHP 5. However, if you are familiar with OOP then you would know that a lot of compromises had to be made in order to offer PHP 4 support. This is one of the primary reasons some developers including myself avoid to use CodeIgniter.
Even if you decided to use CodeIgniter, I still strongly recommend you build your application using PHP 5 and proper OOP techniques.
PHP >= 5.2.3
PHP >= 5.1.0
All the DBMS supported by PDO (PHP Data Object).
* Note: Support for Active Record is limited by DBMS. Currently, only the following DBMS are supported:
- MySQL 4.1 or later
- PostgreSQL 7.3 or later
- SQLite 2 and 3
Yii is the youngest of the three, therefore has the smallest community, it is however growing rapidly as the framework itself gains more attention. Yii offers a forum, a project hosted at Google Code and a documentation section that supports user comments.
Documentation / User Guide
CodeIgniter is known for its excellent documentation. Its user guide is comprehensive, easy to follow and up-to-date. Every release of the framework contains a copy of the user guide too, in case you are maintaining more than one version of CodeIgniter applications.
Kohana’s documentation has been improved since my last article. It now has coverage for most aspect of the framework. However, some parts of the documentation are out of date and sometimes incorrect.
I’ve been using Kohana for a long time now and I found the documentation sufficient and very helpful. It may not have the fine layout found in CodeIgniter’s user guide, but it certainly helps me track down features and usages.
The documentation of Yii seems to be fairly well constructed even though I haven’t started using Yii. All new features or changed features are carefully documented so you know what is going on with the specific version of Yii you use. The API documentation is also very useful thanks to the fully documented code base. However, many features at this stage are not documented in the guide, you need to go through the API or the code base itself.
Tutorial / Sample Availability
CodeIgniter has a dedicated wiki page for all the tutorials, and you can dig around their forums to find more.
Kohana has a dedicated page for tutorials, but is out-of-date. It also hosts a learning centre which unfortunately has not been updated since September 2008. You can still head over to their forums to find useful tutorials though.
Yii has a cookbook section that contains a selection of tutorials. As always, check their forums to find more.
All three frameworks use the MVC (Model-View-Controller) architecture.
* Helpers are undocumented but are referenced in the guide and in the API. All of the helpers can be found in the utils folder under the main framework directory.
CodeIgniter via 3rd party libraries
Yii 1.0.3 has added support for modules.
Unlike CakePHP, all three frameworks offer flexible conventions. There are some defaults but most of them can be overwritten or configured.
CodeIgniter has a fairly good configuration system.
Kohana has an exceptionally well configuration system.
Quoted from the guide: The file structure of config files follows Kohana’s file structure. Meaning that configuration files in the application directory take precedence over those in modules which take precedence over those in the system directory. The one exception is config.php which is hardcoded into the application/config directory and cannot be moved elsewhere.
Yii has a fairly good configuration system.
Database Abstraction and ORM
CodeIgniter has a very powerful database class. It offers query builders as well as database manipulation classes, however it has no built-in ORM support.
One important thing that needs clarification is that even though CodeIgniter has Active Record, it is NOT the same Active Record pattern people commonly refer to. CodeIgniter’s Active Record is merely a collection of query builders.
The most notable time saver during my project development has to be the ORM. Kohana offers a lightweight but useful ORM implementation. It’s not as sophisticated as the Rails Active Record module, but it does the job quite well. I especially love the ease of updating many-to-many records.
Yii has a more complex syntax for declaring model relationships than Kohana. However, it also offers more powerful features such as named scope, albeit the syntax is nowhere near as clean as Ruby on Rails’.
Auth and ACL
CodeIgniter via 3rd party libraries
CodeIgniter has a couple of 3rd party Auth and ACL libraries, please head over to their forums to find more.
* A more complete Auth + ACL solution is being cooked for the 2.4 release. Check out Samsoir’s replies in this thread.
Yii has built-in support for both authentication and authorisation. As I have no first hand experience with Yii yet, I can only judge this feature from the documentation, by the look of it it’s fairly easy to use and flexible enough for most systems.
CodeIgniter’s form validation library.
Kohana’s validation library.
CodeIgniter only supports basic file system based page caching.
Kohana offers a slightly more useful cache library that supports file, SQLite, APC, eAccelerator, memcache, and XCache based caching, with tag support.
Similar to Kohana’s implementation, Yii supports memcache, APC, XCache and DB based (default to SQLite) page and segment caching.
CodeIgniter’s session class is fairly good, it supports database storing as well as handling flash data.
Similarly to CodeIgniter, Kohana also offers a very good session library.
Yii provides a much more powerful and flexible session class. Unfortunately session at this stage is undocumented in the guide. Flash data is not part of the session classes but part of the Auth package.
Logging / Debugging
Yii has a logging/profiling class that is just as powerful and flexible as Kohana’s.
All three frameworks encourage the use of native PHP for templating.
CodeIgniter alternative syntax available
CodeIgniter also provides an alternative template parser class.
Kohana alternative syntax available via 3rd party libraries
Kohana has no built-in alternative template syntax support. However, you can find some 3rd party ones such as Temper.
Yii alternative syntax available
Yii also provides an alternative template syntax borrowed from Prado.
Helpers are usually libraries that used for simple, repetitive tasks.
CodeIgniter offers 21 built-in helpers.
Kohana offers 19 built-in helpers.
Yii offers 6 built-in helpers.
CodeIgniter has an XML-RPC class.
Kohana has no built-in support for any web services.
Yii has SOAP support.
CodeIgniter provides a basic language class.
Kohana provides basic locale and language support.
Yii provides a more complete i18n class.
CodeIgniter has a very basic unit testing class.
Kohana has no built-in unit testing support in the distributed release version (v2.3.1). However, a unit test module can be found in SVN trunk.
Yii has no built-in unit testing support.
Verdict from round 1: There is no right or wrong in which framework you use, everyone has his own taste. For me, CodeIgniter’s excellent documentation and Kohana’s strict PHP5 + easy to use are the primary reasons to choose them over say, CakePHP and Symfony. That said, CakePHP, Symfony and other frameworks are all excellent choices depending on your taste and experience. On one hand I envy the Ruby community because they obviously have the de facto framework to work with, on another hand, we have more options hey? :)
At this stage I can’t comment on Yii, but I am very tempted to developing at least one project using it. So far I am reasonably impressed by the features it offers. :)
Do you have anything to say about the frameworks? Found mistakes in the article? Start the discussion in the comments! :)
- Added Kohana Auth/ACL and DB PDO references.
- Kohana unit test module and template parser reference.
- Wording and other minor tweaks.
- Initial post.