Home » PHP » PHP MVC Frameworks » Yii vs Zend vs Code Igniter Comparision

Yii vs Zend vs Code Igniter Comparision

January 6th, 2011 Leave a comment Go to comments

Choosing a PHP framework is not an easy task, especially if you have relatively little experience in PHP to know what makes a good framework or and what doesn’t, but choosing the right PHP framework for the job is absolutely critical in the long term as choosing the wrong PHP framework can lead to a number of negatives, such as longer development time, need for more experienced staff who may be hard to find and of course performance problems.  Unluckily (or perhaps luckily) when it comes to PHP there is such a plethora of PHP MVC Frameworks that it’s damn hard to actually boil them down to the final choice.  With ASP.NET for example it’s quite easy (although it’s gotten a little more complicated lately), previously there was only ASP.NET but now there’s also ASP.NET MVC, which is very different development paradigm and has it’s own catches.  However, one thing with .NET is that you need to choose how you’re going to do your data access, etc, but with most PHP Frameworks there is usually only one or two ways and they tend to do the job quite well.  So, now with this brief introduction, here’s the thoughts on Yii Framework (1.1.5) vs Zend Framework (1.11.0) vs Code Igniter (1.7.2).

Firstly, why did I decide to actually compare Yii Framework vs Zend Framework vs Code Igniter?  Well, the reason is actually pretty simple… These are pretty much the only 3 frameworks I would consider or rather they are my final 3 of like over 10 PHP Frameworks that I’ve looked at.  The reason Symfony isn’t in this list is because is too damn big and slow and unless you’re building some crazy huge enterprise project it’s not something you’d want to use as it’s slow (and why would you use it when you have Zend Framework).  The reason CakePHP isn’t in this list is because it really forces into doing things the way it wants you to do things and the moment you want to get into something a little more out of the ordinary (which often I do to improve performance) it can’t handle it and it’s also quite slow.  The reason the likes of DooPHP, Solar, Akelos, Prado, eZ Components, Seagull, WASP, etc aren’t in this list is because they’re not quite at the scale (in terms of user community) I would want them to be to actually be considered to be in this top 3 list.  Many of them are outdate and aren’t being developed further or are just akward to use and slow or short on features.  The reason Kohana PHP isn’t in this final 3 list is because I just don’t like the way it’s been written… If you’re an experienced OO developer and you crack open Kohana you just get lost… it’s all over the place.  It’s not a true OO PHP framework in that it uses the paths and all kinds of craziness to do overriding instead of just using plain old inheritance.  All this means additional file system operations and just plain ugliness, and the user community isn’t all that strong like it is for the top 3.

Now, in relation to the top 3 frameworks, being Yii Framework (my preference), Zend Framework and Code Igniter.  Firstly I’ll talk about Code Igniter and Zend as to who they’re my second and third preference as opposed to my first preference (being Yii Framework).   In fact I would have to say that Zend Framework and Code Igniter share an equal second for me as they’re just so different that it’s not really possible to say one is better than the other and should be chose over the other.  I also have to say that I have quite a bit of experience with PHP frameworks, having written some, reasearched others (including actually cracking the code open and tracing through the execution using Eclipse PDT and xDebug) and used the top 3.

Firstly, I’ll start with Zend.  Zend Framework is actually quite a nice framework in terms of it’s completeness and the fact that it is properly designed in terms of OO and lets you do things the way you want to do them without forcing you to learn some new language like Yaml.  However, I have a number of issues with Zend Framework.  For one it’s very verbouse… that is, you often have to write a fair bit of code to do something simple.  This is fine for an experienced developer, but still takes time and time is money.  The second issue I have with Zend Framework, and for me this is the real deal breaker, it is damn slow if you don’t have opcode caching, so if you’re looking to use it for something that will be hosted on a shared server and/or doesn’t have opcode caching, just forget it!  The reason for this poor performance is that the classes are split between so many files that you basically end up doing a hell of a lot of file system operations to load all the classes.  The last thing, which seems to be a deal breaker for many people is that it’s damn complex and the learning curve can be quite steep who isn’t familiar with Patterns of Enterprise Application Architecture (I strongly urge you to read Martin Fowler’s book if you want to become a good OO programmer and easily understand the likes of Zend Framework).  There’s probably a few other smaller drawbacks I could list (e.g. using text and xml based configuration instead of harnessing the power of PHP arrays for configuration like Yii), using long class names (which is needed to overcome the lack of namespaces prior to PHP 5.3) and a few other little things, probably not worth mentioning.  So from this perspective, Zend Frameworks kind of comes in as being too big and complex and that’s the reason for not choosing it.

Now for Code Igniter.  There are a few things about Code Igniter that people really love, being the huge community and the simplicity.  It is not doubt quite an easy framework to pick up for a novice, however, it also has a number of drawbacks.  Firstly, the current version of CI being 1.7.3 is still backwards compatible with PHP 4.  This means un-necessary code and all kinds of other crap.  The second thing is that although it’s quite a complete framework it actually lacks many of the things you actually want when you develop serious complex applications (not just some little amateur website). These things include proper support for templates, user controls (or widgets as they’re called in Yii), integration with jQuery (which I dare say is now the defacto standard for client side frameworks, since it’s now supported by Microsoft) and all kinds of other little things.  When you look under the bonnet you also see alot of ugliness… I mean it’s nice simple PHP code with a few unnecessary things in my opinion (e.g. check if the functions exist, using EXT to define the .php extension and appending that onto everything), naming and lack of code completion support in PHP IDEs such as Eclipse PDT and Net Beans and just plain ugliness.  Sure, it’s nice that it’s nice and simple, but it just isn’t quite there.  I would really love if there was a framework as simple as code igniter in it’s structure, but which used more proper OO techniques, the likes of Autoloaders, didn’t do unnecessary stuff like define .php in a separate constant which is appended everywhere and so on.  I’d be more than happy to manually instantiate the objects I required in some init file and do a few more things manually rather than relying on the framework to magically do them for me.  If there was such a framework I would more than happily use it for little projects, but unfortunately there isn’t one.  The closest thing I have found to this is the PHP Pro MVC framework tutorial and the framework used in OpenCart (although I thing it has some shortcomings too).  Unfortunately, Code Igniter is not this framework and falls short of what I would want for a simple framework.

Finally, I come to Yii.  I guess the thing with Yii is that it fits in nicely right between Zend Framework and Code Igniter.  It’s probably not the simplest to learn for a PHP or OO novice, but for an experienced OO developer it’s a breeze.  It has great documentation and if need be you can always inspect the code yourself.  I actually spend quite some time developing in ASP.NET and Yii feels very very similar.  It has used some of the best concepts from ASP.NET and from many other frameworks and because it’s strict PHP5 and strict OO (without crazy hacks that are typical of inexperienced PHP developers) it’s very very easy to learn and understand as long as you understand the basic principles of OOP even if you have little experience in PHP.  The thing with Yii is that it’s more comprehensive than CodeIgniter and better structured, yet smaller and more robust than Zend Framework, requiring a hell of a lot less code to get stuff done, while giving you all the same features and more (e.g. Code generation with Gii).

So, I ultimately think any experienced architect/developer will come to the same conclusion in terms of the best 3 PHP Frameworks but the ultimate choice is really going to depend on your needs and experience.  I guess the important thing with all 3 is that it’s easy to find resources, as these are probably the most widely used php frameworks these days.  In terms of choosing, if you’re doing a large scale enterprise project then I guess you might not have much choice but to go with Zend as it’s has a company behind it, it’s proven and so on, but be prepared to spend a fair bit of competent staff and hosting.  For a hobbyist or someone just starting out with PHP and not much experience with OO programming, CodeIgniter might be the way to go as it’s nice and simple and pretty easy to get your head around.  It’s also nice and light and has a very large user community and availability of resourced to learn from.  If you’re an experienced developer but don’t want to waste time writing lots of code to do simple things and don’t want to pay an arm and a leg for hosting, but want something that’s mature, well designed and nice middle ground between Zend and Code Igniter then you’ll probably choose Yii Framework like I did.

Hope my rant helps people with choosing the right framework for their needs and I’m always open to feedback.  Also, if anyone knows of a lightweight PHP framework, which doesn’t try to be too smart and is pure PHP5 OO then I’d love to know about it.  I don’t believe that such a framework needs to have stuff like ORM, ActiveRecord and all other bells and wistles, just needs to be lean, mean and fuctional.  Perhaps if you’re interested in writing such a framework I’d also be very much interested in hearing from you and perhaps even conributing.

  • Share/Bookmark
Categories: PHP MVC Frameworks Tags:
  1. October 13th, 2011 at 02:58 | #1

    Sure, good points. To be honest I don’t spend a lot of time reading over the blog posts as they’re exactly that, just quick thought dumps.

  2. October 18th, 2011 at 09:07 | #2

    Symfony is the worst choice , i’ve dealed with it on the open source product “OrangeHRM” it take toooooooooooooooo much time to view the page , and very complex and makes me unhappy to deal with it

  3. November 14th, 2011 at 20:53 | #3

    Nice post. I’ve been involved in many projects since couple of years, have used CodeIgniter, Drupal (which is CMS with modular approach), CakePHP and so on. Drupal is something else so I won’t bring it in this topic. But when it comes to frameworks, I’ve used CakePHP as well as CodeIgniter.

    When I used Yii, I was amazed how quick I was able to generate a grid with pagination and search (within 3 mins or less I guess). If I call some framework that helps in Rapid Application Development, Yii is the one or is maybe enough close. When I compare Codeigniter, or CakePHP, we always have to code (although CakePHP had some bake material which helps).

    The problem with Yii is that it’s not yet in as much demand as other opensource solutions. For example, Drupal has marketed itself so strongly between the customers as well as developers community that even customers are looking for their projects to be in Drupal. And when we talk about CodeIgniter, then this is something really easy and hence, Developers choose it. (It does have good performance as well, compared to other frameworks)

    My experience with CakePHP, and the reason I don’t usually go with CakePHP these days, is that it’s documentation is not that good as compared to CodeIgniter (plus, I was amazed with some further research seeing the excellent performance of CodeIgniter).

    When it comes to Yii, I’m a little bit hesitant to use it as I haven’t seen it being used to an extensive level or massively yet, but I do plan to use it once I get some time to test if things go well with it.

    Whether a person goes with Yii or any other framework, I think the need for today’s frameworks to realize is the Rapid Application Development process, and we as developers don’t want to spend much time in generating Login forms, Table grids, creating paginations and basic search forms, etc. It would be good (like Yii has taken a step into this) that we can generate in few clicks or commands great piece of code, and then focus mainly on the Business Logics rather than creating basic components. Thoughts?

  4. November 17th, 2011 at 08:00 | #4

    Yii has been used for a few big projects like Stay.com. The thing that kinda shits me with Yii is how you’re more or less forced into ActiveRecord. ActiveRecord works nicely for simple stuff but isn’t so great for anything more complex. There are ways to get around that in Yii by using CFormModel, but then you kinda loose a few things that make Yii so good for RAD. It’s also a bit annoying that many things are missing so one has to go looking for functionality to Zend framework or standalone libraries like SwiftMailer. I guess best way to go is to use Yii for all the web stuff and supplement it with Zend components or other libraries for everything else.

  5. John
    December 2nd, 2011 at 03:19 | #5

    Great article!

    My questions:

    1) What do you think about this comparative? http://doophp.com/benchmark

    2) What your expectative about the modifications to new 2.0 Yii version?
    “Our next major release Yii 2.0 will be a complete rewrite of the framework on top of PHP 5.3.0+. It will not be fully compatible with 1.1.x. ”

    Thanks!

  6. December 3rd, 2011 at 12:32 | #6

    I am not a fan of Doo PHP as it’s quite minimalist and quite poorly architected. As for Yii 2.0 I don’t think that’s quite there yet so not something I have looked into as I need something practical. Mind you Yii 1.1.x will work quite well on PHP 5.3 as well, just doesn’t use all the PHP 5.3 features like namespaces and so on.

  7. kmergen
    December 20th, 2011 at 11:17 | #7

    @admin
    I think it is very easy to use DAO instead of ActiveRecord.
    DAO performed better (often 10 x times faster) than AR and it is nearly simple to write the code.

  8. December 20th, 2011 at 23:51 | #8

    Yes, using DAO is certainly not difficult but the problem is that you loose a lot of the benefits that Yii provides because of it’s tight integration. Yii is great if you have full control over the database and are designing a solution ground up with a simple one-to-one mapping between tables and models, but it is not extremely well suited to anything where you have a significant disjoint between the app you’re writing and the database. You can still get it to work and use CFormModel as the base instead of CActiveRecord and then do the shuffling between the DB and the models manually using DAO, but Yii guys don’t provide much guidance in this regard.

  9. Julian
    January 3rd, 2012 at 17:38 | #9

    Hi,

    I came to this post looking for information about Yii framework after I have been using CodeIgniter for 3 or 4 years. I am software engineer and have been working with Java, .NET, PHP and some other languages in the past and should say that I got surprised to read that

    “For a hobbyist or someone just starting out with PHP and not much experience with OO programming, CodeIgniter might be the way to go”.

    CodeIgniter worked really great for me although I didn’t use it for Hobby, but for real applications instead.

    Well, right now I think you can update your article taking in consideration CodeIgniter 2.x instead of the old 1.7.x

  10. January 3rd, 2012 at 23:15 | #10

    CodeIgniter is not a bad framework, but it’s very simplistic relies on old methods of incorporating external code (i.e. hooking) instead of the OO patterns. It’s a good framework to get started with for beginners, but more experienced OO programmers are quite likely to find Yii or Zend to be far more powerful and robust. CI 2.x is an improvement on CI 1.7.x but it still very much relies on old techniques and OO workarounds. For example one thing that really shits me with CI is the naming practice… Why have CI_ prefix for everything and then not use it in the classes. This sucks for code completion. The appoach taken by Yii and/or Zend is far more logical and works far better with IDEs.

  11. jake
    January 10th, 2012 at 12:12 | #11

    then there’s http://www.phpontrax.com which is fast and lite.

  12. January 11th, 2012 at 23:19 | #12

    Yes, but like with many other frameworks the issue is adoption! Zend Framework, CodeIgniter and Yii are all mature and have quite a large user base. In any case Yii pretty much does what PHP on Trax does anyway and I dare say is more feature rich.

  13. January 19th, 2012 at 00:23 | #13

    It is a mostly accurate but slightly unfair review, I think you should be less opinionated to call this a fair comparison, but thanks for taking time to write this review anyway, it helped me have a snapshot idea of yii which I haven’t tried before, and if you’re right and I do like it myself I’ll find you and buy you a beer!

  14. January 19th, 2012 at 21:29 | #14

    No probs. Yii is nice for simple stuff and where you have control over the DB right from the word go, but for anything a little more serious or where you’re working with an existing DB I would recommend Zend Framework. CodeIgniter is nice and simple (and pretty efficient), but it tends to use the older style php programming and isnt’ all that well supported in the IDE because of how it does certain things (e.g. loading of classes).

  15. sz
    January 22nd, 2012 at 11:06 | #15

    New guy to the list http://fuelphp.com/ namespaces, migrations, orm, console

  16. January 27th, 2012 at 07:25 | #16

    Every serious web site is looking for performance and good framework. Zend is cool and can do a lot, but performance is it’s Achilles’ heel. So the core needs to be Yii imo… About queries, the Yii Cookbook compares the 3 types:
    Active Record – Best for Prototyping selects. Update, delete, and create actions for single models (model gives a huge benefit when using with forms).
    Query Builder – Best for working with large amounts of data, building queries on the fly.
    SQL (DAO) -Best for complex queries you want to do with pure SQL and have maximum possible performance.
    Approx. benchmar fetching records from Sakila MySQL Sample DB with version Yii 1.1.9 (using the book sample code)
    Active Record – Time: 0.72791, memory: 15.55MB
    Query Builder – Time: 0.20691, memory: 11.57MB
    SQL – Time: 0.19295, memory: 11.54MB

  17. January 29th, 2012 at 23:05 | #17

    The problem is the size of the community for something new like FuelPHP. I’d stick to something like CI, Yii or Zend for those reasons alone.

  18. Sampa
    January 31st, 2012 at 08:39 | #18

    MyBB chose Yii for building MyBB 2.0.
    And the awesome PHPMyAdmin replacement Chive is also built on Yii.

  19. Tyler
    February 26th, 2012 at 00:42 | #19

    You should take a look at Lithium PHP over at http://lithify.me/ — it’s sick

  20. March 4th, 2012 at 23:16 | #20

    Yes, Lithium is quote prominent with PHP 5.3, but I think it still has a rather small user base in comparison to some of the others I’ve discussed.

Comment pages
  1. January 7th, 2011 at 02:52 | #1
  2. June 20th, 2011 at 08:21 | #2
  3. June 26th, 2011 at 16:08 | #3
  4. July 21st, 2011 at 10:37 | #4
  5. November 17th, 2011 at 06:24 | #5