NEWS: Freelancer? Find something for yourself! Our list of Web Design Jobs »

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.
vendor('Zend/Pdf');$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.
vendor('Zend/Service/Delicious');$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.
Verdict
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.
Discuss  |   Share  |  Sink
Comments Who Floated Related Links