2010年6月8日 星期二

Choosing a PHP Framework Round 2: Yii vs Kohana vs CodeIgniter

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.

Yii: The 1.0 release of Yii had my attention, but I didn’t really dive into it until about now. However, most of my impressions on Yii are based on its documentation and this article by Daniel.

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:

CodeIgniter 1.7.1
Kohana 2.3.1
Yii 1.0.3

Licensing

CodeIgniter Good

CI uses a modified, generally regarded as more restrict, BSD/Apache-style license.

Kohana Excellent

Kohana uses a new BSD license.

Yii Excellent

Yii uses a new BSD license.

PHP Compatibility

CodeIgniter

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.

Kohana

PHP >= 5.2.3

Yii

PHP >= 5.1.0

Supported Databases

CodeIgniter Excellent

MySQL
MySQLi
PostgreSQL
MSSQL
Oracle
SQLite
ODBC
Kohana Good

MySQL
MySQLi
PostgreSQL
MSSQL
PDOSqlite
*Note: Kohana devs have decided long ago NOT to use PDO. Kohana 3.0 is planned to offer support for PDO.

Yii Excellent

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
Community

CodeIgniter Excellent

CodeIgniter is blessed with a strong, active community that is friendly and helpful. CodeIgniter offers a forum, a bug tracker and a wiki.

Kohana Good

Kohana has a small but elite community. It offers a forum, Trac and IRC.

Yii Good

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 Excellent

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 Good

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.

Yii Fair

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 Good

CodeIgniter has a dedicated wiki page for all the tutorials, and you can dig around their forums to find more.

Kohana Good

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 Good

Yii has a cookbook section that contains a selection of tutorials. As always, check their forums to find more.

MVC

All three frameworks use the MVC (Model-View-Controller) architecture.

CodeIgniter Yes

Apart from the standard MVC architecture, CodeIgniter also offers libraries, plugins, helpers and hooks.

Kohana Yes

Apart from the standard MVC architecture, Kohana also offers modules, events, libraries, helpers and hooks.

Yii Yes

Apart from the standard MVC architecture, Yii also offers components, modules, extensions, view widgets and helpers *.

* 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.

Modularity

CodeIgniter via 3rd party libraries

CodeIgniter does not support modules out-of-box, but you may use 3rd party libraries such as HMVC or Matchbox to achieve similar effect.

Kohana Excellent

Kohana not only offers modules, but also has cascading file system which takes modularity to a higher level.

Yii Good

Yii 1.0.3 has added support for modules.

Conventions

Unlike CakePHP, all three frameworks offer flexible conventions. There are some defaults but most of them can be overwritten or configured.

Configuration

CodeIgniter Good

CodeIgniter has a fairly good configuration system.

Kohana Excellent

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 Good

Yii has a fairly good configuration system.

Database Abstraction and ORM

Definitions: Database Abstraction, ORM

CodeIgniter Good

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.

For ORM, please check out IgnitedRecord and DataMapper. Interestingly enough, despite their naming, IgnitedRecord uses the Data Mapper pattern and DataMapper uses the Active Record pattern.

Kohana Good

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 Good

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.

Kohana Good

Kohana has a built-in Auth module and a number of 3rd party Auth and ACL libraries including my Authlite.

* A more complete Auth + ACL solution is being cooked for the 2.4 release. Check out Samsoir’s replies in this thread.

Yii Excellent

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.

Validation

CodeIgniter Excellent

CodeIgniter’s form validation library.

Kohana Excellent

Kohana’s validation library.

Yii Excellent

Yii’s validation usage. All of the system validators can be found in the validators directory under the main framework directory.

Caching

CodeIgniter Limited

CodeIgniter only supports basic file system based page caching.

Kohana Good

Kohana offers a slightly more useful cache library that supports file, SQLite, APC, eAccelerator, memcache, and XCache based caching, with tag support.

Yii Good

Similar to Kohana’s implementation, Yii supports memcache, APC, XCache and DB based (default to SQLite) page and segment caching.

Session

CodeIgniter Good

CodeIgniter’s session class is fairly good, it supports database storing as well as handling flash data.

Kohana Good

Similarly to CodeIgniter, Kohana also offers a very good session library.

Yii Excellent

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

CodeIgniter Good

CodeIgniter has a basic error handling class and a profiler class.

Kohana Excellent

Kohana has a good logging class as well as a more flexible profiler.

Yii Excellent

Yii has a logging/profiling class that is just as powerful and flexible as Kohana’s.

Templating

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

Helpers are usually libraries that used for simple, repetitive tasks.

CodeIgniter Excellent

CodeIgniter offers 21 built-in helpers.

Kohana Excellent

Kohana offers 19 built-in helpers.

Yii Limited

Yii offers 6 built-in helpers.

Bundled JavaScript Library

Bundling JavaScript does NOT mean you have to use the bundled JavaScript. In fact, I encourage the use of unobtrusive JavaScript than using the bundled classes.

CodeIgniter None

CodeIgniter has no bundled JavaScript library.

Kohana None

Kohana has no bundled JavaScript library.

Yii jQuery

Yii has jQuery bundled, and it provides a number of useful classes such as auto-complete.

Web Services

I recommend integrating Zend Framework for web service uses.

CodeIgniter Limited

CodeIgniter has an XML-RPC class.

Kohana None

Kohana has no built-in support for any web services.

Yii Limited

Yii has SOAP support.

Internationalisation

CodeIgniter Limited

CodeIgniter provides a basic language class.

Kohana Fair

Kohana provides basic locale and language support.

Yii Good

Yii provides a more complete i18n class.

Unit Testing

I recommend using SimpleTest or PHPUnit for your unit test needs.

CodeIgniter Limited

CodeIgniter has a very basic unit testing class.

Kohana None

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 None

Yii has no built-in unit testing support.

The Verdict

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! :)

摘自:http://www.beyondcoding.com/2009/03/02/choosing-a-php-framework-round-2-yii-vs-kohana-vs-codeigniter/

沒有留言:

wibiya widget