Zend frustration

Posted on February 13, 2011

Several months back I wrote a few posts about the Zend framework. Since then I’ve worked with it on my own a bit, and I have to admit that my happiness with it has diminished for a number of reasons.

My current project has us using Code Igniter. While there are plenty of aggravations with CI, one place where it wins out over Zend, in my opinion, is its handling of parameters. Suppose you have a page where you pass in an ID number – say, /books/edit/42. With CI, all you need to do is add that parameter to the function:

function edit($book_id)

With Zend, you have two choices. The first is to style your URLs like /books/edit/book_id/42, but that’s unwieldy and a bit gross. The alternative is to build a specific route for the parameter in the config, and then pull it in:

routes.bookedit.route = 'book/edit/:book_id'
routes.bookedit.defaults.controller = book
routes.bookedit.defaults.action = edit
$book_id = $this->getRequest()->getParam('book_id');

It would be nice if you could modify Zend to allow you to get a parameter on the fly, something like:

$book_id = $this->getRequest()->getParam(0);

And indeed, on a previous work project we did that. Unfortunately that was build on Zend 1.7, and four iterations later it’s a huge pain to do something like that. I haven’t seen a lot from Zend Framework 2, but I’m hoping they correct this.

Another gripe I’ve got right now is in Zend’s modeling. I’ve been trying to be disciplined and use the default modeling system (in that previous project, we wrote the Zend_Db_Selects by hand) but it’s proving to be aggravating. Suppose I’m building a database of TV shows and seasons. Presumably you’d represent the tables with Zend_Db_Table, so you’d maybe have a Model_Show and a Model_Season, and a show would have one or more seasons under it. So you set up the models to reference each other and all that. The fun comes when you want to grab a show and all of its seasons. The Zend documentation tells you to do it as such:

$show = $showModel->fetchRow($show_id);
$seasons = $show->findModel_Season();

Now, aside from the fact that the magic name in the second line is fairly ridiculous looking, Zend will throw an error if you then try to set $seasons into $show, such as $show->seasons = $seasons;. I understand why it does that from a code perspective, but I don’t want to have to write out the association every time. And what if I add more functionality within the season (say, to get a list of characters)? I’d have to update every call. And I shouldn’t really have to build a helper to magically build this stuff for me. Even if it did it through lazy loading that’d be fine, but that’s not an option, as far as I can tell.

And that “as far as I can tell” is the clincher: even if I wanted to see what my options are, the Zend documentation is really, really obtuse. They have bits of code that have no context to them and don’t work anyway. I honestly don’t know why it’s so difficult to write good documentation, but so many frameworks out there really have an issue with that. The most frustrating part with Zend, at least, is that there’s so much power under the hood, but it’s not clearly elucidated.

Anyway, what all this boils down to is that, when I want to sit and hack on a few things after work, I want to make actual progress – not have to wade through a bunch of documentation and Stack Overflow posts to get a single answer. And I think that means that, at least for my own little projects, I’ll be looking elsewhere.

Leave a Reply

Your email address will not be published. Required fields are marked *