Skip to content


My Experience with PHP Frameworks

A couple of months ago I first heard about, and quickly started using the Yii framework for PHP. It’s the third framework I’ve ever used, after Ruby on Rails and Zend (the latter is also for PHP), and so far I’m really pleased with it. In this, my first post on Yii, I’ll share my thoughts on frameworks and introduce Yii. In later posts, I’ll discuss some tips and tricks I discovered with respect to Yii specifically.In order to contextualize my thoughts on frameworks, it helps to know a bit about me and my background. First, here are what I consider to be the benefits of frameworks:

  • Rapid development
  • Theoretically more secure
  • Easier to maintain

Frameworks are great if you do a lot of Web sites or if you work in a team, where different people might work on different aspects. On the other hand, frameworks:

  • Take a while to learn and master
  • Are much harder to customize
  • Can perform more poorly

I primarily work by myself and while I’ve done a lot of Web sites in the past ten years, I don’t do a lot in any one year. What I primarily do are very custom, dynamic sites, trying to give the client (and their end-user) exactly what they want without any compromise. For these reasons, I didn’t even consider using a framework until Ruby on Rails, in 2005.

By now most people in the industry have heard of Ruby on Rails and I will say that it does live up to the hype. It’s ridiculously easy to rapidly put together fully-functioning sites. Rails is just fantastic. Yes, there may be performance issues, but I don’t think that’s truly a concern for most sites. If you’re creating a top-tier site, like an ESPN or Amazon, you probably don’t want the overhead of a framework. On the other hand, with such sites, you also have the resources to throw tons of hardware at the performance problem. The main downside of Rails—for some people—is that you really have to know Ruby in order to use it. For those out there that only know PHP, that’s an issue…

When it comes to PHP frameworks, there are lots out there, with different features and backgrounds. I’ve heard very good things about CodeIgniter, Cake, and Symphony, but I choose to learn the Zend Framework when I started looking into this. Mainly I started with Zend because it’s well documented and supported. Plus, I wanted a PHP 5-specific framework, as the object model in PHP 5 is so significantly improved from PHP 4, that I believe any framework that runs on PHP 4 is just not taking full advantage of what’s possible.

So I went through the Zend tutorials, making a couple of quick sample sites. And I read a book on the Zend Framework and used a lot of its documentation. After a month, maybe two, I had had enough. I feel like I never quite “got” the Zend Framework, perhaps because it’s too complicated, perhaps because the perspective being used in the book I read and the online documentation were too different. In any case, Zend felt like a whole lot of work: everything just took more effort than I felt it should. For just the most petty example, all of the view files goes within a views directory, then organized by controller in there. That makes sense. But in each controller subdirectory, the view files have to go within a scripts subdirectory. Sure you can change this configuration, but it just seems like an unnecessary extra step. I felt like I was spinning my wheels a lot and getting nowhere fast, so when I heard about Yii, I decided to check it out…

The Yii framework is really new, but is written for PHP 5 and developed by a person behind the popular Prado framework. Yii does not have much in the way of documentation, but what it does have makes a lot of sense to me. In the end, the fact that I was able to easily understand and use Yii sold me on it, but at first what I appreciated was:

  • It uses jQuery by default for its JavaScript (Zend uses Dojo by default, but jQuery is possible through other extensions).
  • It easily supports third-party extensions (for example, the documentation shows how you can use the Zend Framework Lucene search component in Yii).
  • ActiveRecord is a common basis for the models (this may or may not mean much to those new to frameworks but I value it).
  • It creates the code for you!

With this last point, Yii behaves much like Ruby on Rails. Using a command-line tool, you can immediately create models and CRUD—Create, Read, Update, and Delete—functionality. For example, you create a model using the command model User. Then create CRUD functionality using crud User. At that point you’ll already have a Web site where you can add, select, update, and delete a type of information called “User” (likely this would correspond to a User table in a database). The site will paginate records, validate data, provide detailed error messages, etc. From there you just need to modify templates, tweak forms, set permissions, etc. The default site template also creates basic login functionality, too.

I’m about 85% finished on my first Yii site, which is rather complex (23 database tables, three user types, multiple layouts, etc.), and am very pleased with my decision to use Yii. In fact, I quickly had to whip out CRUD capabilities for another site so that the database could be populated, and I was able to get that ready for the client in 3 hours! In subsequent posts I’ll talk about the MVC (Model-View-Controller) paradigm in some detail, as it’s the foundation for most frameworks, then get into using Yii in detail.

Posted in PHP, Web Development.

Tagged with , .


4 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Farmer Gary says

    Would you be willing to share the URL for a site that uses Yii or similar framework? Preferably, one you created. I’d like get an idea for what kind of website uses 23 database tables, three user types and multiple layouts.

    • Larry says

      Hello, Gary. Thanks for the request. I’ll be happy to share the URL once the site’s live. But I can say that the three user types are: admin, subadmin (ability to manage some of the content), and general visitor. The home page uses one layout, other pages have their own layout with a different header and sidebar. There are 23 database tables because there are lots of kinds of content, with different templates and different permissions. Many of these content types have related subtypes, so there’s a Publications table and a PublicationTypes related table. As I said, I’ll gladly share this later, but I don’t know how obvious it’ll be that it’s so complex on the backend.

  2. Farmer Gary says

    Thanks for sharing. My own website currently has 10 databases. I just added another one for storing events such as automatic reorders, delayed shipping, customer reminders, etc. Being my own website, I’m always adding and changing stuff around. I also have various user levels (boss, admin, cashier, registered user, visitor) but it’s all store in a single user type. For the most part, my site is a simple little e-commerce site.

    Overall, I feel like I have a poor sense for the internal workings of other websites, especially larger ones. I can read through open source code like OSCommerce or ZenCart but that is very different than custom written code. I love seeing how other people solve things because it often gives me good ideas on what I can do with my own site.

    • Larry says

      Hey, Gary. I assume you mean 10 tables, not 10 databases, right? But, yes, seeing what other people do is a great way to learn. After a while, database design and such becomes second nature.

If you need quick assistance with a question or problem related to one of my books, please use the support forums instead.

Some HTML is OK

or, reply to this post via trackback.