Zend Framework: First Impressions

Introducing the Zend Framework

Last week, the first production release of the Zend Framework was released. I've taken some time to read through the documentation to understand what each of the components do. And you know what? I think I like it.

What is it?

A powerful high-quality open-source framework focused on developing modern Web Applications and Web Services

That's how Zend describes the framework. What's interesting is that it isn't an out-of-the-box MVC framework. It's really just a collection of classes that can help you build your web application. The site is clean and there is plenty of documentation. The manual runs through each of the classes describing what they can do and how to do it.

Zend has a heavy focus on web services with ready-made components for Akismet, Amazon, Audioscrobbler (for Last.fm), Del.icio.us, Flickr, Google and more. Most of these build on other components such as the HTTP, REST, JSON and XMLRPC classes.

They also have all the makings of an MVC (Model-View-Controller) framework with the Controller class. Tie in the DB, Filter (for filtering data), Cache, Auth (for handling authorization) and ACL (Access Control Lists) classes and you've got the ingredients for a decent framework.

In many ways, I feel like Zend sits on one end of the automation spectrum with CakePHP on the other end and CodeIgniter (CI) sitting in the middle.

Automation scale: CakePHP on the more side, Zend on the other end with CodeIgniter in the middle

CakePHP and Zend sitting in a tree

As most of you probably know, I currently use CakePHP to power this site and I'm definitely a fan of the framework. But one area where I felt that CakePHP didn't cover was a lot of the additional components that come with CI or Zend. I've always felt that this was extremely minor as it allowed the developer to pull in whatever components that they want to use. For example, I used a Flickr class to create a simple gallery in CakePHP. I use a compoenent called kses for providing HTML filtering for my comments. CakePHP's flexibility makes it a really great system to work within.

But where does one find high-quality classes focused on developing modern web applications and web services? Enter Zend Framework! And the integration with CakePHP couldn't be easier. Just drop the Zend Framework into the vendors directory. (Keep in mind that while CakePHP can work with PHP4 or 5, Zend Framework is PHP5-only.)

You'll need to modify the include path to point to the root of the vendors folder. What I did was simply add a new line to my app/config/core.php.

ini_set('include_path',ini_get('include_path') . PATH_SEPARATOR . '/path/to/vendors'); 

Anytime you want to use a particular class, just use the vendor function to load in the class. After that, you're free to instantiate the class.

$pdf = new Zend_Pdf();

And just like that, we're creating a new PDF document.

Implementing the Del.icio.us class

To really give it a spin, I decided to try out the Del.icio.us component as I plan to roll out some minor changes here on Snook.ca. I figured this would give me a better sense of how well it was designed.

The first thing I was looking to do was replace the quick links in the sidebar to a del.icio.us powered component. This was very straightforward as it's one of the first examples on the documentation page.

$delicious = new Zend_Service_Delicious('username', 'password');
$deliciousposts = $delicious->getRecentPosts('forsite', 5);
$this->set('deliciousposts', $deliciousposts);

Then, all I have to do is iterate over the results in my view. In this case, I created a list item and link for each entry using the title and notes for the text.

foreach ($deliciousposts as $post) {
echo '<li>'.$html->link($post->getTitle().' - ' .$post->getNotes(), $post->getUrl()).'</li>';

The next thing I wanted to do was include a count on the page as to how many times a particular page was bookmarked. Unfortunately, this wasn't so easy. The Del.icio.us API describes has a way to get information on a post via the URL but, for some reason, this seemed to be left out of the ZF Del.icio.us class. Well, that sucked. Why apparently implement the all of the API but one method?

In any case, a little digging through the ZF code and it appeared that getting this going could still be straightforward. After some trial and error, it turned out to only be a couple lines of code:

$delicious = new Zend_Service_Delicious();
$parms = array('hash'=> md5('http://example.com/archives/my/article_url/'));
$delicious_post_total = $delicious->makeRequest('feeds/json/url/data', $parms, 'json');

That's it! You'll notice that because this is a public method that I don't have to specify a username or password when instantiating the Del.icio.us class.


I was a little disappointed in the lack of the one method I needed in the Del.icio.us class and trying to reconcile the Del.icious API against the ZF API was a minor frustrration. All-in-all, I was still very pleased with how easy it was to implement and I have plans to use a few other of the classes as well.

I'll still be sticking with CakePHP for building MVC-based applications. The automation it offers me is just too powerful to give up. However, I see Zend Framework as being a great companion to it.

Published July 10, 2007 · Updated July 10, 2007
Categorized as PHP
Short URL: https://snook.ca/s/834


28 Comments · RSS feed
Nate Klaiber said on July 10, 2007

Nice overview. I like the way you incorporate it with the CakePHP framework. I recently spent some time in the ZF documentation as well and really liked what I saw. As you stated, it isn't a full blown framework (which is what I think confuses people), but is a great library to build a foundation. I love the coding style of the ZF - very clean and able to be extended.

Look forward to some more tips on integrating with Cake :)

Peter said on July 10, 2007

Smart idea, dropping the Zend Framework into Cake. I am also a Cake user and I was interested in trying Zend, but I definitely wouldn't have thought of using them both together anytime soon. That really is the power of cake in action.

I was actually considering creating components for CakePHP to integrate with a bunch of webservices that I had planned to use with a site I'm developing, this is going to save me a lot of time.

Matthew Weier O'Phinney said on July 10, 2007

Jonathan -- I've posted a feature request for you on the ZF tracker for the del.icio.us bookmark total:


Jonathan Snook said on July 10, 2007

@Matthew: many thanks for adding the feature request. More importantly — and something I didn't really explain well in the article — is that the call that I make actually returns a bunch of info on the URL including common tags, etc. It's only within the view that I actually pull out just the count from that data. Therefore, to have it added to the API, it should actually be getUrl($url), from which it could have the getTitle, getNotes, and other methods including getCount.

Jonathan Snook said on July 10, 2007

I should add that the ZF issue tracker is a piece of beauty. I love how they show a simple bar chart comparing the number of open requests per component. Love it.

Kevin said on July 10, 2007

It's also worth noting that ZF integrates well with Symfony - http://www.symfony-project.com/weblog/post/135.html, although I'd wait a bug to be fixed with the sfZendPlugin before it'll be using the 1.0 version (it currently uses 0.9.2).

Masklinn said on July 10, 2007

I should add that the ZF issue tracker is a piece of beauty. I love how they show a simple bar chart comparing the number of open requests per component. Love it.

It's Atlassian Software's JIRA bug tracker.

It's not free, it's a bit on the expensive side in fact (the cheapest license -- standard for Academics -- starts at $600) but it's the single best bugtracker I've ever seen, in looks, in functionalities and in interface quality.

Ian said on July 10, 2007

Thanks Jonathan for the quick review.

I had tried ZF about 3 weeks ago (just before final release) and found the components to be great but the documentation to be old - full of depreciated code and missing a lot of functionality. I hope this has changed.

It's interesting that you have used it with CakePHP. You've inspired me to try the same.

That said, ZF is a full framework with support for a MVC architecture. Of course it doesn't have the automation of CakePHP and in this age of 'time is money' this in my book is a significant limitation.

Masklinn wrote: It's Atlassian Software's JIRA bug tracker...It's not free

Actually, it is free for non-profit organisations and open source software projects.

Yannick said on July 10, 2007

Nice little overview of ZF and comparison with CakePHP. I've played around with it a bit and it is a nice and comprehensive framework. I would consider using it depending on the project I'm undertaking, however for the most part I'm still a big fan of CodeIgniter and find it easier to use. With that said though, just as ZF can play nice with CakePHP and Symfony, it can also be integrated with CodeIgniter as the following article shows:


Just thought I'd point that out, in case anyone was wondering.

Tarique Sani said on July 10, 2007

The post and comments amply indicate that ZF will be great as the glue which you can use to paste together stuff in most of the existing MVC framework and this I feel is as cool a marketing trick as it is a technology trick.

I am looking forward to a Bake like script for ZF and most likely it will come from one of its users rather than the core team

brainfault said on July 10, 2007

The main problem of ZF, IMHO is the fact that there is no easy way to handle complex views, this problem raise more than once in the mailinglist, there's some solutions that emerged mainly the padraic brady's one, a solution is planned "Zend_View_Layout" and it's high on the priority list, despite that ZF is a great framework with a lot of of interesting components which I use daily through the symfony zf plugin.

Sharandeep Brar said on July 10, 2007

Good Articles. I also use cakephp for most of my work but was slightly confused after zend framework release. But as shown by your article that zend framework components can be used easily inside cakephp, i think i would be able to keep using cake and also have some ZF components goodness.

Ryan Brooks said on July 12, 2007


Since I remember asking you your opinion about ZF quite some ago when you were all gung ho about CakePHP, I was disappointed to hear your reaction to ZF. I've been using the framework since 0.2 and it has come a long way since then. I wouldn't consider ZF to be a MVC framework; moreover I think it's a bundled library to encourage rapid application development, with components such as MVC. As brainfault said the biggest problem with it is that it can't handle complex views, albeit it has come a LONG way since it started.

I look forward to seeing a more detailed post (hopefully) as to why you'll stick to CakePHP versus ZF for MVC applications; maybe someone such as myself can offer a rebuttal. ;)

Jonathan Snook said on July 12, 2007

@Ryan Brooks: not sure why you're disappointed. I did say I liked it and that I had plans to continue using it.

CakePHP really shines because of the automation. I can unzip the framework, configure the database, create the tables and then run a script to generate everything. In 5 minutes I could have an application. Zend isn't "out-of-the-box" in that sense. I have no doubt that someone will create a sub-project that does offer that out-of-the-box step but for now, CakePHP meets my needs and when it doesn't, I've now got Zend among others to rely on.

Ji31 said on July 12, 2007

I like your blog a lot and I read it constantly. I would like to ask you, what editor do you use for writing of CakePHP and why?

Thanks for answer

Jonathan Snook said on July 12, 2007

@Ji31: Right now, I mostly use UltraEdit. It's just a super-fast text editor which code highlighting and some other handy features. I'm actually going to try and switch editors to something a little more feature-full.

Emil said on July 14, 2007

Ji31: I would recommend Zend Studio, it has code completion.. both for php's built in classes/functions and for your own. It's a time saver, especially if you like name your classes with good names which sometimes can be hard to spell :-)

Al Newkirk said on July 25, 2007

I am not new to PHP but I am new to Zend, CodeIgnitor, and CakePHP. I am an Asp, PHP and Perl programmer and I have been using CodeCharge Studio for years using thier framework. What do you think. http://www.codechargestudio.com

ionCube said on July 27, 2007

An interesting summary. When we were looking at frameworks recently we looked at the Zend framework, and whilst it looked promising at first glance, about as quickly as we realised that it wasn't really there yet, we realised that Cake was much more in line with what we expected to see. Having now used Cake for a while we're very pro Cake, although we realised that Cake isn't without some fundamental flaws too although these can be dealt with. ZF does have some useful components, and leveraging those within Cake is a great idea and highlights one of the cool things about Cake, which is that it's easy to extend.

gd said on July 27, 2007

I just start learning CakePHP. Nice article.

Matthias Willerich said on August 01, 2007

I like the concept of adding Zend classes to CakePHP. As you're the one who got me started actually using Cake instead of just looking at it, I might follow this advice rather sooner than later.

IlMagnifico said on August 30, 2007

No doubt, Cake is really a great FW and ZF is a powerful (and very clean, though a liitle beta) collection of classes, why not use them both together?
I played around with Cake for months now and also recently checked ZF.
The most important point that gives me headache using Cake for my next projects is: why in the world Cake is PHP4-compatible and doesn't use the power of PHP5 (like ZF).
PHP4 is about 6 years old, there is really no need for using it anymore. Or do you still use another six-year old applications or programming languages?
Stop propagating PHP4, please. That's the main reason why PHP is still full of bad-named and inconsistent functions and naming.

For me it's a clear No-Go issue for using Cake in serious projects.

Nick Ohrn said on August 31, 2007

Thanks for the great review of this framework and it's integration into CakePHP. I'm looking right now at starting to use some frameworks in my work to speed up dev time, and this looks like a great solution.

DCramer said on September 04, 2007

I've taken a look at the framework and my conclusion is that It doesn’t offer much more than a concise set of classes as you mentioned. they are indeed helpful however the only time it saves is looking up classes on phpclasses or searching Google.

This however does bring in a greater deal of quality through the Zend Framework's classes as they are tried and tested and work well together. But I'm not sure of calling it a framework as much as a library or extension set. I feel a frame work should be more what the name implies. a system to mold your application over. Something that include layout structures as well as classes working together to deliver a application designed by the developer.... but that just me :)

I do however like the classes and they are amongst some of the best I've seen and surely will use them in some of my own applications.

jb said on November 19, 2007

I had never used a php framework before and decided to give the Zend framework a shot - it is wonderful. Creating and consuming webservices became ... fun. I'm still learning my way around it, but I've enjoyed Zend thus far.

bazet said on October 15, 2008

Nice arguments on Cake ZF. Actually, I plan to integrate ZF within my CakePHp to use thier Youtube API. I develop a simple forum using cakephp in 1 week ( http://forum.protonmania.com )...still got bugs and I need to optimize the query by using containable behavior..cake just rocks.

Oliver Treend said on January 18, 2009

Ooh! In addition to Ji31's question and your response, does UltraEdit highlight PHP code in your .ctp view files?

I use EditPlus, and it doesn't highlight the PHP code because it's not got the PHP extension. That really bugs me! :-(

Oliver Treend said on January 18, 2009

No worries! I just looked in the EditPlus settings and found out how to turn on syntax highlighting for .ctp files!

In case anybody else would like to do the same:

  1. Go to Tools > Preferences.
  2. Click on Files > Settings & syntax
  3. Choose 'PHP' under 'File types'
  4. Add ";ctp" to the end of the 'File extensions' box.
  5. Click Apply/OK and watch your .ctp files burst into colour! :-D
Sorry, comments are closed for this post. If you have any further questions or comments, feel free to send them to me directly.