Zend Framework and Doctrine

doctrine_iconWell it’s looking like Doctrine is the heavy weight data mapping solution of the lot. Zend Framework was often criticized for having no serious Model methods. Models was just sort of where you put your nuts and bolts database code. Some folks like the structure of the Active Record model that you see in Rails some other PHP frameworks. Sure it makes it dead easy when your tables map pretty straightforwardly onto your objects but makes it harder to have complex objects involving many tables. Zend was working on their own Zend_Entity package to remedy this, but they have abandoned it in favor of integrating Doctrine. The Zend Roadmap for the future calls for tight integration of Doctrine with the framework, so there will probably be some additional automatic linkage, with the view to the framework user’s code being smaller. But both ZF 2.0 and Doctrine 2.? are for PHP5.3, which is some time down the pike for ordinary folks. On the ZF Wiki there is a proposal to integrate current versions, at least to some extent. The symfony camp are hollering that Doctrine automatically “just works” in symfony, and that’s great. But for now you do have to do a little work to integrate it with ZF.

So first thing to do is get my head around Doctrine. The manual for it spends a lot of time going through the various things you can specify, and shows you how the PHP code is isomorphic to a yaml specification. This is fairly straightforward. The DQL seems straightforward too. You just have to remember that you *PRECONFIGURE* all the ON’s for relational table joins so you just have to tell it what you want. And then it is a matter of getting fluent using all the methods it defines.

I started by having a look at the Doctrine Sandbox, and that worked for me pretty easily. I then advanced to the doctrine tutorial, and that also worked without a hitch. But now we have to confront the 800 lb. gorilla in the room: Zend Framework

The problem with integrating it with Zend Framework seems to be autoloading and how to best integrate the whole thing with the bootstrapper. I’ve collected a bunch of links related to this for now, and may eventually get it together enough to publish my own solution. But here is what I have: I’m trying to extract the essence of this so that I can have my own way I feel comfortable with and not slavishly copy any of these. In the interest of sharing, I’ll just post the links here, then when I’ve digested this rather large glom, I’ll comment. Feel free to mention any more that you know in the comments:

16 comments to Zend Framework and Doctrine

A sample text widget

Etiam pulvinar consectetur dolor sed malesuada. Ut convallis euismod dolor nec pretium. Nunc ut tristique massa.

Nam sodales mi vitae dolor ullamcorper et vulputate enim accumsan. Morbi orci magna, tincidunt vitae molestie nec, molestie at mi. Nulla nulla lorem, suscipit in posuere in, interdum non magna.