Back to the blog
Recent Posts
-
Aug 31
A bit of icon work
-
Jun 24
Your mobile OS can't really multitask...
-
Apr 27
Thoughts on Android and the HTC Dream
-
Feb 26
Announcing Twitterscribe: archive your tweets
-
Jan 01
Adventures in PHP interfaces
-
Oct 17
How do you mockup websites?
Most Popular Posts
-
Why you should be using a framework
-
Dynamic methods in PHP
-
Rewriting URLs with Apache's mod_rewrite and PHP
-
Five easy things that make you a better web developer
About the Blog

I'm a web application developer in Melbourne, Australia. If you find anything useful, leave me a comment, and if you need web design, development, or accessibility and usability consulting, contact me! Cheers.
Twitter: joshsharp
There's No M in Zend
A quick review of Zend Framework 1.0.0
Sunday 05 Aug, 2007 06:40 PM
Zend are the company behind the development of PHP itself, as well as a lot of professional PHP tools, such as the Zend Optimiser, which optimises and caches code (as the name implies). So it was with a bit of enthusiasm that I read the news that Zend Framework 1.0.0 had been released. I've been looking around for a decent PHP framework for a while now, and eventually settled on writing one myself. There are pros and cons to each way of working – with your own code, you can leave out the irrelevant parts, and write something that makes sense to you and operates as you wish. But on the flip side, you can't beat the polish and sheer size of a community-built framework.
Zend Framework promises:
- A modular structure – only use what you need
- A full MVC framework
- considerable extensibility
- A sprawling mass of modules covering everything from authentication to a built in Amazon Services API.
It was the modular nature of Zend that made me prick up my ears. As far as frameworks go, I'm more in favour of those that offer less 'magic' in their functionality. CakePHP, for example, does a lot of the work for you by generating magic data accessor methods, and can even create 'scaffolding' which implements a CRUD frontend for your tables. I didn't like the way it forced you to name methods and database tables for it to work, though, and ended up writing a framework which uses extended data objects in a way that makes more sense to me. (Interestingly, Jonathan Snook reviewed Zend Framework also but liked CakePHP's automation more.)
But back to the Zend Framework. Aside from some core modules, Zend lets you only use the modules you need, although it does provide an MVC framework which I imagine most people would use. It is the MVC implementation that irked me the most about Zend.
Learning UI design at uni (in Java no less – it really made me appreciate the Visual Studio IDE), MVC structure was driven into us quite thoroughly. Models were for data, views represented the user interface, and controllers handled the business logic. And in an ideal system, there wouldn't be any overlap. Most of my apps aren't quite that perfect, but I like to work towards that idea.
Zend Framework, though, seems to be a little confused as to how MVC should work. It's very big on controllers, to the expense of the models, and views to a lesser extent. Controllers in the Zend world handle nearly all of the logic, including SQL queries and data manipulation. In my eyes, this is bad form. Data manipulation should be handled by data objects (the model). But there doesn't appear to be a model in Zend's idea of MVC.
And when it comes time to display something to the user, there is very little that can be done to the view. What about presentation logic? I understand the idea of keeping all PHP out of the view, but personally I'm not adverse to a foreach loop for each of my items, for example. However it seems this is frowned upon in ZF. And the idea of 'partials', or pieces of a page that can be rendered into the page, is also missing. It looks like implementing common sections across different views is a clumsy process.
I really wanted to like Zend Framework. It has many useful modules, and is undoubtedly better written that my little framework. But its flaws irk me, so for now I'll wait. Perhaps the next release will be truly MVC.
Comments
As to the M, I've written several projects using Zend Framework and I prefer heavy models vs. putting your code in the controller. I normally use the controller to do as it's name implies, control things. It sets up the models, handles handing things off to the view, etc. It is possible to put all your code in a controller and totally ignore the model...but I don't know anyone that recommends it.
IMHO, etc.
=C=
I think you misunderstand me, though. I'm totally with you as to using the model to handle all the data functionality - as you say, controllers should just control things.
It's just that I couldn't find much evidence of model usage in ZF. Is this because the framework encourages BYO model code, or have I missed something fundamental?
It's OK, I forgive you.
So I decided I'd create my own framework too... It doesn't have all of the bells and whistles of ZF/Cake/etc, but I can tweak it to my hearts content. :-)
