Integrating Doctrine with Zend Framework PDF Print E-mail
Written by Joshua D Miller   
Friday, 01 May 2009 14:45
Article Index
Integrating Doctrine with Zend Framework
Adding Doctrine to the Bootstrap
Creating the models
Updating the Controller
Conclusion
All Pages

For the Filecab project, I chose to employ Zend Framework for the business tier. However, being very familiar with the Doctrine object-to-relational mapping (ORM) library for PHP, I chose to empoy it in lieu of Zend Framework's Zend_Db component (which is still in its infancy in terms of functionality). This blog shows how to integrate Doctrine with Zend Framework - and how easily Zend Framework can be used with 3rd party libraries.

For more information on Zend Framework, see my previous blogs on PHP frameworks and Zend Framework specifically. I am using the latest releases of ZF (1.8) and Doctrine (1.1) for this blog. Please note that this blog will NOT apply to earlier versions of ZF as it employs the new component Zend_Application.

What we need to do

To show how easy I found it to be to integrate Doctrine with a Zend Framework application, let's just use the Zend Framework Quick Start guestbook example as a starting point.

This blog assumes the reader has a familiarity with both Doctrine and the Zend Framework Quick Start guestbook example. You can read the Quick Start guide or obtain the code from Zend here: http://framework.zend.com/docs/quickstart.

Okay, so here's what we've got when we finish the Quick Start:
Quickstart
|--application
| |--Bootstrap.php
| |--global.php
| |--config
| | `--application.ini
| |--controllers
| | |--indexController.php

| | |--errorController.php

| | `--guestbookController.php

| |--models
| | `--Guestbook.php

| `--views
|   |--scripts
|   |--guestbook
|   |  |--index.phtml
|   |  `--sign.phtml
|   |--index
|   |  `--index.phtml
|   `--error
|      `--index.phtml
|--library
| |--Zend
| `--doctrine
|--public
| `--index.php
`--scripts
`--doctrine-cli

In order to modify this to use Doctrine instead of Zend_Db, we need to do the following:
  1. Add Doctrine information to the Bootstrap class
  2. Create the Doctrine model classes to match the existing Guestbook database tables
  3. Update the Controller to use Doctrine classes instead of the Zend_Db classes
  4. Update the Views to use the Doctrine classes, as well
The rest of this blog explores these steps in more detail.


Last Updated ( Thursday, 21 May 2009 14:40 )
 

Open Source Projects Josh Supports :

   
Fedora Project   openSuSE Linux!   Ubutnu - Linux for Humans  Spread Firefox Affiliate