Zend Framework
July 29, 2008 – 1:24 pmThere are numerous web application frameworks written in and for PHP on the market nowadays, most of them free and/or open source, most of them following or supporting the MVC paradigm. This summer, I’m going to go and attempt to make a website using one of the newer frameworks out there: the Zend Framework. Made (or at least started / supported by) the people / company that also does the PHP language itself, it promises a solid framework for web application development, ‘extreme simplicity and productivity’ (from the website), up-to-date with the latest internet technologies, etcetera.
In this post (and following posts), I will dive into Zend Framework, describe its various loosely-coupled components, and make an attempt at judging the framework.
For this summer vacation, I had decided to start my own website project, just to keep up-to-date and whatnot. Since PHP is the most supported scripting language (and currently supported by my relatively cheap host), I decided to do it in that - much less hassle trying to get it online. Although PHP isn’t my favorite language, I decided to give it another serious try, with everything I’ve learned of OO programming and design during the last few years.
Earlier, I’ve played around with Ruby on Rails, the web application framework that sparked an enormous flood in MVC frameworks in various programming languages - amongst which PHP. I even made a simple site with that, got some hosting for it (which was quite more expensive than my current host), and attempted to put it online… but that failed.
Later, I played around with CakePHP, a very popular PHP framework that, as other frameworks do as well, offers an MVC structure, an object-relational mapper, AJAX support, and all that and then some. I didn’t finish the website I started to built with it (due to uncertainties with the people that were going to use / run / operate it and my own lack of interest), so I am not able to properly judge CakePHP. I was annoyed by how you insert variables in templates though - when I attempted it, you had to echo an array index from an object field:
$something->post['Post'];
or something like that - I can’t remember. Looking at the current quickstart, they’ve changed it to echo-ing a structure like
$post['Post']['id'];
but that still isn’t to my liking - it’s an array in an array in an equally-named variable. If there are multiple posts, which is the only reason I can think of why you’d use a two-dimensional array, at least call your variable $posts (plural), and run through all the posts with a foreach loop or something.
Anyways, that was probably more than a year ago. So this summer, I finally decided to start working on my own website and, following some rumours on the internets about Zend Framework, I decided to give it a try.
The Zend Framework is in a lot of respects the same as all those other PHP frameworks out there, having a database abstraction layer, MVC support, AJAX support, and all that. The main thing that ZF stands out for however is that it’s all loosely-coupled - using one component of Zend Framework, for example the database layer, does not mean you also have to use their MVC component, and vice-versa. There’s a list of components of the Zend Framework in the programmer’s documentation, and for the biggest part, they all work independently of each other. For example, if you want to configure your database connection (using Zend_Db), you can do that by passing an array of the configuration parameters, or you can use an instance of Zend_Config, which can also be initialized in multiple ways (by using an ini or XML file, or by passing a PHP array). These decouplings and lack of dependencies between Zend Framework components is one of the major points in the entire framework. It doesn’t force you to use one or the other. Want to use your own controller structure? No problem. Want to use a third-party database abstraction layer? No problem either.
Zend doesn’t force you to use anything, it leaves you with the choice. And I believe that is a very good philosophy.
So far, I’ve spent a good week or so on the framework, progressing through the development by reading the documentation on one component, then building part of my application using that, followed by reading up on another component, and intergrating that into my application. It’s relatively easy to remodel an existing application to use Zend Framework components, or to add additional functionality to your program. Which I find a nice way of working, since you can take learning the framework one step at a time, whenever you’re ready for it.
So far, I’ve only used a small part of the Zend Framework - Zend_Controller, Zend_Db, Zend_Form, Zend_Filter, and Zend_Validator conciously. Some more components are used unconciously, such as Zend_View and whatnot, but it’s possible to replace those as well. As such, I’m nowhere near providing an accurate description or review of the framework. However, in the week or so I have noticed several things, both positive and negative.
First, there’s quite a lot and thorough description of each component in the Zend_Framework, which explain the biggest parts of each component. There’s also a complete API available, although the documentation on that isn’t very extensive - three-worded method descriptions and such, for example. With that, the documentation is just ‘good’, not perfect. But since the framework is still in development, with the 1.6 version being released as a release candidate not too long ago, I’m sure that’ll come along soon.
Next, there are serious demands for new framework components. They have to have an 80% test coverage, proper documentation, adhere to the coding standards, and so forth. The test coverage requirement is, in my perspective, especially valueable, since it gives some degree of guarantee that the framework is good in terms of quality. I haven’t actually seen the tests (or even executed them) yet, but I do plan on writing tests for my own application, once I have a basic version done.
However, not everything is fine and dandy with the Zend Framework. While it does offer a large set of components, it isn’t really intended to be a full website framework. For example, it isn’t shipped with an object-relational mapper (yet), or with scaffolding purposes, which, for other frameworks, are often used for advertising purposes (as in: lookie me! I can make a blog in 5 minutes!). This means that some components, such as object / relational communications have to be written by the developer himself. The Zend Framework makes the development of a website a lot easier, but doesn’t take all the work from the developer. This can be seen as both a good and a bad thing. It’s good because it allows a lot of freedom and control for developers, allowing them to control pretty much every aspect of their website, without relying on auto-generated code or underlying functionality. It’s bad however because it’s not very easy to learn for new users. The latter part can probably be solved by both extensive documentation (a full tutorial isn’t yet available) and frameworks built on top of the Zend Framework, that do add features such as scaffolding to the framework. Such features might be added to the framework itself in a future date.
All in all, I like Zend Framework. It doesn’t seem to be aimed entirely at new developers, isn’t pretentious or promising instant websites, but offers a professional framework for serious developers that know what they’re doing, without forcing their hand into using components that may not be applicable for their particular situation. I’m also unable to judge whether the Zend Framework is suitable for (relatively) new programmers either. I’m not having any serious learning problems with it, since I like to tell myself I know proper object-oriented programming, but I can imagine that new programmers will have problems with it, due to it giving a lot of freedom, requiring a lot of design knowledge, and the absence of step-by-step guides for building a full website.
In the near future, I’ll (probably) be writing some more articles concerning the Zend Framework and/or components therein.
EDIT: My bad, the Zend Framework does have some sort of object/relational mapper, in the form of the Zend_Db_Table and Zend_Db_Table_Row classes, which represent a database table and/or table row. The latter one in specific is the OR-mapper, and allows you to call methods like save() to store a row into the database. I’ll try and write an article on it once I figure it out properly for myself and I cba.
Tags: Frameworks, PHP, Zend Framework








1 Trackback(s)