I have been programming using the Zend Framework for some time, one thing I have always been aware of is that it seems to be trying to be very much like Rails. Both are MVC so there are going to be similarities but with each new version of the Zend Framework we get closer to what Rails has.

At least that’s what I thought and confirmed very quickly when I started learning Rails yesterday evening.

Rails gives you alot more out of the box than Zend does, it had been a while since I used a new version of Zend so I decided to start from scratch on my most recent project. I found myself very quickly following the getting started guide where it got me to do a bunch of stuff (like add the autoloader) that I just felt should already be there.

If you use Zend_Tool to build a Zend Framework project but don’t turn on the autoloader I want to hear from you.

In rails, the first thing I did was run one command on the command line which generated me a database table, built some controllers and models. I got the functionality to view, add, edit and delete records straight away. In less than a minute.

The Zend Framework is just not this quick yet, and people will probably tell me that no mature rails developer actually uses the scaffolding because nothing is ever as simple as the code you get; But in the case of the project i am working on now, I spent the better part of a day in Zend writing the most basic of forms to insert data into a table (no joins, nothing clever).

Another feature I love in Ruby, is validation in the models, which carrys through to anything that manipulates the data (via the model of course).

Have a look at how simple the code is, the Zend Framework could only dream of it being this simple right now:

class Product < ActiveRecord::Base
  protected
    def price_must_be_at_least_a_penny
      errors.add(:price, 'should be at least 0.01') if price.nil? || price < 0.01
    end

  validates_numericality_of :price
  validate :price_must_be_at_least_a_penny
  validates_presence_of :title, :description, :image_url
  validates_uniqueness_of :title
  validates_format_of :image_url,
                      :with	=> %r{\.(gif|jpg|png)$}i,
                      :message => 'must be a URL for GIF, JPG ' + 'or PNG image.'
end

Related posts:

  1. Zend Framework Code Generator I released this little script for the Zend Framework today...
  2. Validate URI’s, Check files exist on http and ftp with Ruby on Rails During my Ruby education, I decided I wanted to create...

Related posts brought to you by Yet Another Related Posts Plugin.