15 Jan 2010

Easy PHP Websites with the Zend Framework

By W. Jason Gilmore

I was after a good solid introduction to the Zend Framework (ZF from now on), but from the Amazon book reviews all the choices seemed poor. This one had the most promising reviews. It is self-published, the downside of which is that it is only on amazon.com, not .jp or .co.uk. I therefore bought the e-book version.

The first four chapters show the more traditional way of making web sites, without using ZF. They kind of feel redundant; they are aimed at beginners and not about ZF. They could be motivating for how easy ZF makes things, but (see below) that isn't the case. However as an introduction to PHP development they are okay.

Chapters 5, 6 and 7 cover the ZF way of writing applications (i.e. the split into model/view/controller), how ZF deals with databases and how ZF handles forms, respectively. In other words the core of a ZF-based website. At this point I have to admit my ignorance. Either this section of the book is doing a poor job of motivating the use of ZF, or ZF is not very good. I suspect it may be the latter, but I will have to do a project or two with it to tell you for sure. Anyway the example code comes across as verbose with no real advantage over the traditional PHP way of writing a complex web site.

I got a bit stuck at this point, and this book gathered electronic dust. But really needing to get up to speed on Zend I forced myself back to it, and I am glad I did as the last third of the book is where it shines. Chapter 8 is about managing users, with a brief coverage of how to make a SNS (social network site). Chapter 9 is on the Google Maps API. Chapter 10 is about integrating with Amazon. Chapter 11 introduces Javascript and Ajax. Chapter 12 has a (fairly brief) look at RSS, then (quite a long) look at Facebook APIs. Chapter 13 covers Google: Analytics (analyzing visitors), AdWords (advertisting your site) and AdSense (making money from ads on your site). Finally, Chapter 14 introduces PayPal, and introduces some third-party shopping cart applications.

Chapters 8 to 14 generally show the underling API, then show the Zend way of doing things if there is one. The exception is chapter 11 where Prototype and Script.aculo.us libraries are introduced (whereas ZF has adopted Dojo). The author tries to claim he deliberately introduces Prototype to show you how to use an alternative library. I suspect it is more like chapter 11 was already written before Zend announced the Dojo tie-up.

What else can I say? The book follows the theme of the GameNomad web site throughout the book, which is a web site to introduce and review people's computer game collections. This is good as it gives context for the features being introduced. The book was updated for Zend 1.9, and hopefully will stay up to date.

The code samples are frequently long-winded. E.g. the fopen/fwrite/fclose sequence is used to save just a single string, when file_put_contents() is both shorter and more descriptive. As another example, the listing on p.244, lines 13 to 19 could be replaced with a single, more descriptive line:
return str_repeat($star,$rating);

There is lots of good stuff in the "PHP framework" (i.e. the function libraries that come with PHP itself) that shouldn't be ignored in the rush to embrace 3rd party "frameworks".

Overall the first two-thirds of this book are nothing special, but the last third is good and makes this book worth buying if you have any interest in "Web 2.0".

$38 on Amazon (US), or $32 directly from the author
The e-book is $22, directly from author.

1 comment:

Frank Drouillard said...

Buy the latest version of his book (2011). I covers ZF 1.11 and introduces Doctrine2.