Zend Framework and fav.or.it
If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!
As we come near to launching fav.or.it I thought I would share my thoughts on building the project completely on Zend Framework. When we started 7 months ago the framework was on version 0.7 and some may have thought that basing our fledgling startup on a single unknown framework was slightly foolhardy. I will first cover why I made this decision and then outline my thoughts on each of the core modules and how we use them.
The Research
When I researched what framework we would use and if in fact we would use any of them I had a whole lot of criteria that they needed to fulfill. I was already well aware of the main contenders (CakePHP, Symfony, CodeIgniter) and then along came the Zend Framework. I immediately warmed to the overall mission statement behind the Framework and also the fact that on top of having a great team of developers they had the steadying hand of a company that had a vested interest in making the Framework a success but also to make it relevant to business as well as to the open source community.
Is it a framework?
The first thing that I always have to explain when talking about the Zend Framework is that to me it is not a ‘framework’ or not in the same way others are frameworks. This causes a lot of confusion and misunderstand of what the Zend Framework has to offer. To me most frameworks require you to conform to how they ‘think’ (something Ruby/Rails suffers from) and breaking out from their thinking requires actual alteration of the framework.
To me the Zend Framework is actually a Library, something that I can pick and choose from and although a good percentage of each module does also interact with other modules this behavior can in most cases be overridden or sub-classed and behaviour changed.
The MVC
Another difference is that a lot of Frameworks revolve around their own implementation of the MVC (Model View Controller) and again if you want to break out from how they work then you may as well not use any of the framework. The Zend Framework does of course include modules that assist in setting up a MVC and it has many great tutorials on ‘the standard’ way of doings things. But once you begin to understand how everything fits together it has incredible power for those who want to stretch its legs.
Not for beginners?
I will at this point make lots of enemies by saying that the Framework is a professional product and is not really for the beginner. Although it has made strides towards simplifying some aspects of the MVC (and other modules) it is still certainly more complex than others and if you have no inclination to do anything ‘out of the ordinary’ then my advice is to use something else.
The Modules
The Zend Framework as I mentioned earlier is made up of a range of modules (full list here) most of which fav.or.it uses at one level or another. I wont go into detail for all of them as I would just be repeating what is said in the manual.
Zend_Acl - Access Control List
I have previous written at length about the ACL and done a podcast on the subject. It is a little hard to get your head around to start off with (the reason I tried to explain it in the PodCast) but it is extremely powerful and versatile.
Zend_Auth - Authentication
Authentication made simple. Although again we have sub-classed and extended the functionality it again got us up and running within hours and then let us think about the more complex tasks by filling in the basics.
Zend_Cache - Caching
The cache is fundamental for anyone who is serious about long term scalability. It allows caching of pages/parts of pages or just raw data. It has two killer features for me 1) Range of backend solutions (File,SQL, Memcache, ZendPlatform) 2) Tagging. The back end options give me great flexibility to choose the right kind of caching for the situation plus it is easy to extend to add your own. The tagging is a delightful way to group together different pieces of information so that they can be cleaned up / listed by tag or tags.
We created a whole new interface so we could view the current state of the various caches we have and allows us to clear out entries by key (every item must have a unique key) or by tag.
For anyone thinking about investing in Zend Platform it also means that when that time comes that any caching can be handed over to the platform.
Zend_Controller / Zend_View
I am a massive fan of well structured MVC’s and the Zend Framework gives me the flexibility to do everything we could possibly want. As default creating mapping between URL & method/controller gives you quick setup. You can then easily extend the routing (how a URL gets translated).
We have a whole set of custom routes, we have a fully sub-classed dispatcher and make use of the helpers when we can.
The Zend_View is quite simple as a starting point but is easily extended and can achieve a range of design patterns. We have various extensions to give us partials and layouts. The partials allow us easy blocks that have local variables assigned to render pages. The layout lets us arrange numbers of blocks/sections.
Zend_Db - Database
I cannot recommend Zend_Db enough! It is at once very simple to get going but fantastically full of depth. I had never considered myself much of a database expert and Zend_Db allowed me to think about the programming problem rather than SQL. The ability to build select statements programmatically with a consistent interface is a dream come true.
Zend_Feed
fav.or.it is all about feed aggregation and Zend_Feed gave us a fantastic head start on consuming and producing feeds. We have sub-classed this heavily as we have a lot of special requirements but it did save us lots of time covering the basics.
Zend_Filter + Zend_Filter_Input + Zend_Validate
I put these all in together as they all have similar tasks. Although at first I found constantly building up filter/validation chains long winded (but very readable) I soon starting building helper functions that let me build the chains with shorter (not sure if clearer) syntax which could then be easily repeated.
e.g.
const FILTER_EXAMPLE = 'Alnum:Alpha:StringTrim'; $string = Filter_Helper::filter(FILTER_EXAMPLE,$string);
The same can be applied for building up Validators. At some point I will release the full syntax and the code.
The Rest
- Zend_Gdata - Easy to use and very powerful, we use it to access blogger services
- Zend_XmlRpc - This is still in its infancy but it still does the job for most tasks
- Zend_Http - Want to perform some custom request? this handles nearly everything, we use it all over the place for a range of tasks and has proved to be very robust
- Zend_Date - Dates come in lots of formats and Zend_Date means you treat them all the same, a few question marks over future performance when over using this
- Zend_Log - Does what it says on the tin, quite lightweight but easily extended to give a few extra features that makes it worthwhile
- Zend_Session - I try and keep clear of over using session data but having the ability to namespace your sessions makes this very useful
Conclusion
The Zend Framework does a fantastic job of giving you a professional quality set of tools to get going with quickly and then when required it doesn’t stop you customizing it when you need to. As you grow more confident and start to understand the underlying reasoning behind the framework you start to work with it more and more and it encourages you to achieve the same kind of extensibility that it has achieved.
php zend zend framework

Trackback by PHPDeveloper.org on 1 October 2007:
Nick Halstead’s Blog: Zend Framework and fav.or.it…
…
Comment by Matthew Weier O'Phinney on 1 October 2007:
Why do you say Zend_XmlRpc is still in its infancy? The component has been well-tested both at the Unit Test level as well as on production machines (both for its server and client). What specifically do you find lacking in it?
Comment by kenrick on 1 October 2007:
Would you mind showing this as well?
Pingback by developercast.com » Nick Halstead’s Blog: Zend Framework and fav.or.it on 1 October 2007:
[…] Halstead takes a look in a new post about how his latest project, Fav.or.it, is using the Zend Framework for just about every part of […]
Comment by Stuart on 1 October 2007:
Ditto on what kenrick said. I came down to the bottom of the page to write precisely what he has written.
Given the flexibility of Views in ZF I am very keen on seeing what others have done to implement the V in MVC.
For what it is worth, on a large website that I am working on the various controller actions are responsible for setting properties and calling pertinant methods and then calling index.phtml. Index.phtml is simply filled with calls to other view files:
echo $this->render('header.phtml');
echo $this->render('foo/bar.phtml');
etc.
It seems far from ideal to me, though it works, and it ends up violating the principles of DRY.
FYI, the upcoming Zend_Layout (not what it will actually be named, from what I can tell) addresses this but is rather complex and still being digested by myself (and the module is still only a proposal… a working proposal but still apt to change).
Comment by Pádraic Brady on 1 October 2007:
Zend_View Enhanced and Zend_Layout are now a single combined proposal - which was approved for development a few days ago ;). So it’s on it’s way. Zend_Layout does look complex from the outset, but a lot of that is all the extra bundling of options. A simple use case is quite straight forward - and ZVE Placeholders, Partials and Actions make it even more so.
I would really like to see a config based approach to Filter/Validate proposed - It would clear up all the verbose setup currently required.
Oh! And best of luck with fav.or.it!
Pingback by eKini Web Development Blog » Blog Archive » Fav.or.it using Zend Framework on 2 October 2007:
[…] those who have doubts in using the Zend Framework, maybe you should this post. As we come near to launching fav.or.it I thought I would share my thoughts on building the […]
Comment by admin on 5 October 2007:
Pádraic Brady, I look forward to the new enchanced and Layout, we put together something that suited our needs but what we have built is very specific for fav.or.it, and for future projects I will be looking at using the built in layout.
I will release the code for our helper for filter/validate in next couple of weeks when I get a chance to write a post about it.
Comment by mike on 9 October 2007:
Hey would like to know if i could get my hand on an invite to fav.or.it You could say I am an expert beta tester, and would help you greatly.