Symfony refactor of the Zend Quick Start Tutorial
Learning Zend Framework and getting a repetitive stress injury doing it
Edit: please see Matthew Weier O’Phinney’s (the current project lead for Zend Framework) response in the comments, there are some exciting things comming for ZF
My friends & colleagues have used Zend Framework (ZF) for a while, and I do my best to avoid it and use the Symfony PHP framework. Initially I was open to learning ZF, I was just curious why people liked it. The more questions I asked, the more I realized there were no good answers other than standards for standards sake, and variations on the Sunk Cost Fallacy. If pressed I was told that I had to give Zend Framework a chance because it is a younger framework than Symfony, (um no). Some of the developers had even written a library to add on to Zend Framework to make it more usable, it contained features that were already in Symfony. IMHO, writing code to help a framework catch up is an excellent reason to switch to another framework.
This last week I was finally forced to use ZF, my rebellious use of Symfony only served to annoy the other developers, and had the potential to increase maintenance costs. It seemed like a reasonable request, and all those developers couldn’t be wrong could they?
Well yes they are. I work with some great people whose feelings I don’t wish to hurt, but I would estimate that Zend Framework projects cost between 20 to 40 hours more for projects that run around ~400 hour plus. With agency rates what they are that could turn in to 6 or 7 thousand dollars of added costs. Assuming requirements for user authentication and backend CRUD’s. These numbers will vary widely from project to project.
From a quick comparison of the Symfony Case Studies and the Zend Framework Case studies I would expect this efficiency gap to continue to increase. A couple of Zend Framework‘s case study subjects have already failed: QEDWiki & PokerRoom.com, and anyone who’s been unfortunate enough to have to customize Magento likely regrets the experience. Symfony’s case studies are large successful projects you may have heard of: DailyMotion, Yahoo! Answers, Delicious, & Yahoo! Bookmarks. To be fair I’ve seen some really nice Zend Framework apps, I’ve just seen more interesting and larger Symfony projects.
A Quick Comparison
To present as fair a comparison as possible I have rewritten the Zend Framework Quick Start as a Symfony app. I also used Symfony 1.2 with the Doctrine ORM, both of which I’ve not used before, as my projects have been in Symfony 1 or 1.1 and the Propel ORM so far.
I’ve formatted this more as a timeline of events rather than a tutorial, however the full Symfony app source is available HERE. To drop it on your web server you will have to change the path to Symfony in config/ProjectConfiguration.class.php, I had it running through WAMP on my local machine.
This also serves to document how I wasted a perfectly wonderful summer morning, *sigh*.
I did change some things around, I used MySQL because I’m not familiar with sqLite and, I used reCaptcha instead of a captcha similar to the tutorials. I think these add difficulty, and are fair changes.
- 9:15am – 9:30am set up symfony app
- 9:30am -9:38am skip a bunch of Zend configs and translating layout to sf
- 9:40am – 9:43am generated controller & view, skipping autoloading in the bootstrap file
- 9:43am – 10:06am set up database
- wrote schema.yml to define guestbook table
- setup database connection string:
- php symfony configure:database –name=doctrine –class=sfDoctrineDatabase “mysql:host=localhost;dbname=guestbook” username password
- 10:06am – 10:20am building model
- php symfony doctrine:build-model (Getters, Setters & Stuff or GSS)
- php symfony doctrine:build-sql (generates the sql)
- php symfony doctrine:insert-sql (inserts the sql into the db)
- skipping the build database script, symfony does that for us
- 10:20am – 10:35am Listing out all guestbook entries in view (got distracted with doctrine, I usually use propel)
- 10:48 am Generating form classes
- configuring to remove created at from view
- unset( $this[‘created_at’], $this[‘updated_at’] );
- configuring to remove created at from view
- random interruptions by wife….
- 11 am writing view layer
- 11:15am writing controller for saving
- Setting up captcha
- Double checked ZF Quick Start to make sure I did not forget anything
- 11:54am done
- under 150 lines of me-written code, including html I C&P’d from the zend tutorial
- this means much less fumble finger type mistakes
- ~2hrs 39 min to complete from httpd.conf setup to form submission.
- with distractions, a mySQL db, and a reCaptcha
- I’ve clearly spent more time complaining about Zend Framework than it would take to complete the mini app in Symfony
- The only config files I touched were
- config/ProjectConfiguration.class.php to use Doctrine instead of propel auto-magically
- config/doctrine/schema.yml to define the db tables
- config databases.yml was set up from the command line so you be the judge on that one
- Configuration done in:
- Bootstrap file configuration
- appliation.ini configuration
- the zf tutorial expects you to write around 515 lines of code to do the same thing as Symfony
- that’s from the tutorial text not the well commented source code.
- Also there promise of a “30-minute tour” can’t mean that you can program it in 30 minutes
Zend Framework is not bad, compared to using plain PHP there are some significant efficiency gains to be made. However, when compared with Symfony and other frameworks, like Django & Rails, it’s missing key features found in modern Web Development frameworks. The tutorial I described here demonstrated the efficiency issues of not having code generation for the Model layer. Two other key features are generated CRUD’s for backend site management, and a full MVC plugins like Symfony, Rails, & Django all have.
The long term ramifications of not having plugins and generated code accelerating your project are corners cut on quality, reduced features, scaling problems, and less competitive bids. The lack of robust plugins in Zend also means that it will never be able have as many features as frameworks that do have Plugins. Not having code generation means that developers are spending too much time writing mindless getter’s, setter’s, & data grids and not enough time focusing on the core features of the project, or worse they are making compromises in quality to make deadlines.
I don’t believe that the Zend Framework is so far behind that it can’t catch up. In certain areas it’s actually ahead of the game, however those areas tend to not be fascinating edge cases I get to use every so often, and not features I use on every site every day. My suggestion for Zend is use the Model layer examples available (Active Record, SQLAlchemy, Doctrine) and do something like that. Doctrine already integrates well with Zend, maybe that would be a good option. Then start generating admin interfaces or CRUD‘s, this is huge, I find all kinds of ways to use these things to add value to my projects with a little typing on the command line. Finally Plugins, the most important consideration when reviewing a framework or CMS. The quantity and quality of plugins demonstrates the quality of the development tool. It also means that there are developers out there that care about the tool outside of the core team.