Starting out with Zend Framework

Zend Framework
I am on a mission to get to grips with using the Zend Framework for building web applications. At MOO, the Zend Framework is used in it's more toolkit-like component library capacity and I'm also pretty familiar with its structure from previous work with Magento (although that always seemed to over-complicate it). Using it as a full stack framework however, is a different challenge all together.

Let me explain the reasons why I'm investing time in ZF. If you've read this blog before you may be aware that I have a lot of experience working with the Symfony Framework, and I'm really fond of it. However after using it to write what was quite a sizeable app, I found it started to get quite slow, as well as finding the ORMs (I mostly used Propel) to be quite cumbersome (I like SQL!). I often spent a long time trying to figure out how Symfony wanted me to do something and therefore the flexibility of ZF in this regard is attractive.

Zend Framework also seems to be more of an industry standard, where Symfony is somewhat niche. Coming from Zend and with training and qualifications available, it seems like a good tool to add to my toolbox. The added benefit is my code & approach are more likely to be understood by other people quickly, so if any of my side projects ever take off they should scale easily :)

Tackling the Tutorials

So on to the task of learning how to approach a site with ZF. I have two books that I've skim-read: Zend Framework in Action and Php|architect's Guide to Programming with Zend Framework both are OK but pretty broad and don't cover key topics in much detail. I've also been through the quickstart tutorial on Zend.com and some of the more advanced stuff. It's clear that Zend Framework is a powerful tool, but mastering it is no simple task.

Flexibility & being able to approach problems in multiple ways was one of the attractions of Zend Framework, but I find the complete lack of even a hint at where code should go quite disconcerting. I would be happy with some suggestions and debates on best practice, but even that seems limited. Therefore I have taken to searching Google for key topics with the flag "-site:zend.com" so that I only get results from sites other than Zend because it is top in all search results but almost never has the answer!

One of the great things about Symfony is the Askeet/Jobeet tutorial. Every version of Symfony has had an in-depth tutorial that went with it, covering each aspect of the system. This provided a great learning tool, and also a fantastic talking point for debate and spin-off tutorials which looked at areas in even more depth.

In complete contrast, the Zend Framework's own tutorials seems to be extremely lacking. Most of the documentation seems to cover only very basic examples, lacking in any real depth or clever stuff. For example the Getting started with ZendAuth tutorial lacks CSRF protection & password salting - two things that should really be "the standard" IMO. The following tutorial on ZendAcl is even more disappointing - it doesn't give any clue as to where any of the code should go. You're expected to know/guess or just make it up as you go.

Finding an Approach for Key Concepts

There are three areas in particular which seem to be vastly under-documented / under-exampled in my opinion: Models, Access Control and Routing. I despise patterns using one model class to represent both a collection and instance of an object, which is what appears in a vast number of tutorials. ZF seems to roughly support the ActiveRecord style pattern (which I'm used to from using Propel/Doctrine) through extending its DbTable & DbTableRow classes and paired with DbSelect it works as a kind of lo-fi ORM. It seems that many Zend folk are not a fan of ActiveRecord, but the main documentation barely hints at any of this, or any other potential approaches. You have to leave the main site and search various blogs to get even a whiff of any of this knowledge.

Even more worrying/frustrating is the seeming lack of documentation around Access Control & Routing. I'm used to these being baked-in in Symfony as both were managed via YAML config files, and the almost-comes-as-standard sfGuardPlugin provided fine grained control of users, groups and permissions. ZF provides tools, but little direction and it seems quite intensive to get either of these key parts of a web application up and running.

Frustratingly, there seems to be no such obvious place to setup these vital parts of the site (does everyone end up with enormous Bootstrap files?!?). I've already mentioned the vagaries of the ACL tutorial, but routing for me is pretty fundamental. In Symfony you define your database schema (which results in a database, models & forms for CRUD), then write your routes, then you write code. In ZF I've really struggled to find anything which takes the same REST API-as-standard approach to configuring routes. I know it can be done, it just doesn't seem to be a standard way of thinking about things.

Zend Framework vs Symfony?

Well, this turned out to be much more of a Symfony vs Zend Framework post than I intended. It also seems that all the features of Zend that I thought would make it great to use have turned out to be what makes it a pain in the arse! I know that this is partially because I've been spoiled by Symfony doing so much of the heavy lifting for me, and by its awesome documentation. I am also aware I'm trying to do ORM-y things without an ORM. It seems that by keeping a tight reign on the approach to key concepts, Symfony had allowed itself to foster a much richer pool of easily-accessible documentation. Also, Symfony seems much more intent on including its community & building great accessible documentation, instead of (or as well as) providing training courses.

Note-to-self: I need to clear my mind of expectations and pre-conceptions about frameworks if I'm going to succeed at this!