Sunday, December 6, 2009

Yii Framework: choosing the best web application framework

After experimenting with a few different programming languages and even more frameworks, I've settled upon a PHP framework called the Yii Framework. This post describes how I arrived at Yii and what other options I considered before making my decision.

Several years ago I wrote a functioning, but ugly and difficult to modify, web application. The code that's in production right now works well, as I spent a lot of time making sure it was solid and had good cross-browser support. However, there are several new features I'd like to add and some issues I'd like to address before it takes off and makes me a millionaire (we all can dream, no?). But the convoluted and frustrating mess of spaghetti code in my original implementation has stalled these ambitions.

For the past few years I have been too busy with work and other projects, and this one has regretfully stagnated. From time to time I felt the itch and would set out to find the perfect language + framework in which to build my application. Following is a rough chronology of my various attempts to rewrite and extend my application using "the best" web application framework.

Attempt #1: PHP + Zend Framework beta

Having experience with PHP, and comforted by the fact that Zend Framework is built by the people who built PHP, my initial foray with ZF seemed like an good idea despite its pre-1.0 status.

The main problem I ran into with ZF was my own ignorance.

  1. I wanted my hand held, but Zend Framework was more of a toolkit than an MVC environment.
  2. This was my first experience with a sophisticated web application framework. Conceptually I thought I understood the Model-View-Controller pattern, but I'd never used one before and didn't fully grasp its nuances or the best practices.
  3. Despite having a few years of experience with Java, I'd only programmed strictly procedural PHP up to that point. In retrospect this really wasn't a major hurdle, but coupled with the other issues it was a contributing factor.

The quick start guide was not nearly as good as it is today, and getting everything set up was frustrating. I thought I was missing the how-to guide that would explain how to get everything the way I wanted and send me on my way. I didn't really understand what a framework was or what ZF offered.

Attempt #2: PHP + CakePHP

After being frustrated by the learning curve and the lack of guidance with Zend Framework I stumbled upon CakePHP and got excited once again. It offered a structured, this-is-how-you-do-it, approach to building web applications.

The lack of documentation in some key areas is what eventually drove me away from CakePHP. I spent many hours trying to get some forms to behave exactly how I wanted them to, and after several days without much to show for it coupled with a few ugly "hacks" in place to get the behavior I wanted, I didn't feel like things were going the way I wanted. Things slowly fizzled out as I became overwhelmed by other projects, and the rewrite halted.

Attempt #3: Ruby on Rails

While considering job prospects after my imminent graduation from college, I briefly got caught up in the Ruby on Rails phenomenon. I ordered a book, built a simple application, and was thoroughly blown away. Everything just clicked. The hype was justified and my only regret was not having taken a look at RoR sooner.

After a while, however, I ran into some issues that nagged me too much to continue on. Ruby on Rails was at first refreshing in its "one way -- the right way" approach to designing web applications. After the agnosticism of Zend Framework I was initially receptive to Rails.

But the considerable, backwards-incompatible differences between the dated version of Rails used in the books I purchased, and the more recent versions, caused several headaches. I spent hours trying to figure out how to do what I considered to be very simple things for common use cases. When I did find the answers I was usually surprised by their simplicity, but the hunt for them was the challenge, and the fact that I was learning Ruby at the same time made progress inch ahead at a snail's pace.

I think I could have been successful with Ruby on Rails if I was more patient at the time, but it required more of an investment than I was willing to give at the time. I did enjoy learning the basics of Ruby, but I was disappointed to discover that it was not my silver bullet.

Other concerns were limited web hosting support, more complicated deployment steps, and various claims of limited scalability. At the time, the first was (and may still be?) a legitimate concern. The other two may not have been issues so much as excuses I deferred to as I shifted my time to other pursuits and stopped working on the rewrite.

I realized at this point that programming frameworks have an up-front investment in time that cannot be ignored. One cannot simply port their code to a framework without learning and accepting the various quirks of the framework (and language). As I only had a small amount of time available to invest and I was looking for immediate results, I shelved the project yet again.

Attempt #4: Python + Django

Quite a bit of time passed since the previous attempt. After hearing about python for years I finally decided to see what it was all about one evening, and found myself glued to the very well-written introductory Python tutorial. After working in Java professionally for quite some time, learning python was really... fun. It seemed to have the interesting superpowers of those languages you learn in college but never use professionally, but with a large user-base, excellent documentation, few technical limitations, wide support and an inexplicable "wow, that's cool" factor.

I took a look at the small selection of viable Python web application frameworks and after much fretting over cutting edge vs. conservative options, settled upon Django. It was really quite easy to get started with but I eventually (inevitably) realized once again that I was starting down a path where I needed to be serious and willing to invest a lot of time if I was going to be successful. I didn't have the time to invest, so things stalled yet again.

Attempt #5: PHP + Yii Framework

After gaining professional experience in a variety of frameworks in a couple different languages, and feeling more disciplined and confident that I can master a chosen language/framework, I have selected the Yii PHP Framework. I make this choice after much research and contemplation, not because I believe Yii is the best framework out there, but because my initial experimentation has been quite enjoyable and when I attempted to solve the issues I faced in previous attempts I found that Yii offered simple, documented solutions.

To be honest, once I settled on PHP as the language this was really a toss-up between Yii and Zend Framework. I investigated ZF's progress since my initial attempt and found that it has really become a lot more solid and full-featured than it was a few years ago. If I had more experience with Python I'd probably be seriously considering that option, but, alas, I'm eager to get something finished quickly and I know I have the skills in PHP to be up and running quickly.

The main negative for Yii is the fact that it is relatively new, and is still technically in beta. Having kept an eye on it for quite some time now, seeing it implemented successfully by several companies, and knowing how brilliant the lead programmer is all give me some comfort that it is a legitimate contender. The other factor that pushed me to Yii is that I can still use Zend Framework components inside my Yii application if I choose.

Why not Code Igniter, newer versions of CakePHP, Symfony, or any of the other myriad of PHP frameworks out there? I can't claim to have fully vetted all options because I simply don't have the time. I took a look at documentation, examples, the size and vibrancy of communities, and even many flame wars between the fanatics of each, and felt that Yii was the best fit for my purposes.

P.S. Please do not take offense to my personal experiences if I had problems with your framework of choice. I know there are experts who can bend each of these frameworks to their will to accomplish almost any task, and I'm absolutely not saying that any of these frameworks is the best choice, or not a good choice, for anybody. These are simply my experiences with the version, documentation and time constraints I faced at the time I tried each of them out. I would enjoy going back and trying out some of these frameworks a second time to see how they have improved since I gave them a spin.


  1. This is a great post. Thanks for sharing!

    I absolutely agree with you about RoR and Django. I feel the exact same way.

    Right now I'm down to Yii and Kohana 3.

  2. Thanks for sharing the experiences. I am in doubt whether to go for Zend Framework or Yii. Now, after reading your post I am inclined to Yii. Thanks ;)

  3. Like you I've been contemplating which framework to use. I'm basically down to ASP.NET, Zend, Yii and Kohana. The nice thing with .NET is that there's a good development tool with a good debugger, compile time checking, etc, and most importantly it can do EVERYTHING you dream of, there's a great community, but dev tools aren't free, hosting is more expensive, especially if you use SQLServer and generally you gotta write more code to get stuff done. Then we move to PHP... Zend is nice and pretty much the .NET equivalent for PHP, BUT it's really heavy and performance ain't all that great. Kohana seems nice but it's a derivative of CI and doesn't have some features i really want. Yii looks great, but is new and also doesn't have some features, e.g. HttpClient. So here I am still considering which way to go...

  4. Thank you for your article. I've had similar experience in the past. But was not even able to follow up with the tutorials for most of the framework due to their complicated requirements compared to the simple PHP script. I recently started to use Zend Framework, but it is very slow and looking for faster one. I wish Yii is the perfect solution for me.

  5. I'll give Yii a try, I'm currently using ZF, it's OK but I fell it's not suitable for me. You have to got the matching feeling to give the best you can, just like I felt with jQuery in client side's area. Thanks for your post, pretty interesting and useful at the same time.

  6. Thanks for an interesting read. I'm looking to switch away from Django (authentication module / hosting requirements etc.) and am debating between RoR and Yii. From what I've read RoR is a pain to deploy, whereas Yii is simple.

    I will miss the Django admin interface though....

  7. Yii is on of the best PHP framework that is easy to use, fast and secure. It works perfect for Web 2.0 applications which non other framework does.

  8. Good Post. I too was researching for a best framework to start with. And was deciding to choose among ROR and PHP-yii. Let me go with yii as I am comfortable with php and apache server.