I\'m interested in using Doctrine as an ORM for a new Zend Framework app I\'m writing. I\'m trying to figure out the best way to integrate it as straightforward as possible.
I wrote a Resource Bootstrapper for Doctrine and Zend Framework a few weeks ago and turned it all into a small wrapper framework, cause I think ZF and Doctrine are a great team. You can read the article here: http://coffeecoders.de/2009/06/using-the-zend-framework-18-bootstrapper-and-doctrine-110/
It is fully configurable via the Bootstrap resource configurations (example included, too). Unfortunately Doctrine searches for Models in the model folder with the same classname as the filename (which doesn't match the ZF naming scheme) so it was actually not possible to get rid of registering the Doctrine Autoloader. The resource Loader looks like this:
<?php
/**
* Doctrine model loading bootstrap resource. Options must provide a connection string.
* directory option for model directory is optional (default is ./models).
* Further options will be set for the Doctrine manager via setAttribute (e.g. model_loading).
* @author daff
*/
class Cuckoo_Application_Resource_Model extends Zend_Application_Resource_ResourceAbstract
{
public function init()
{
$manager = Doctrine_Manager::getInstance();
$options = $this->getOptions();
foreach($options as $key => $value)
{
if($key != 'connection' && $key != 'directory')
$manager->setAttribute($key, $value);
}
if(empty($options['connection']))
throw new Exception("No database connection string provided!");
Doctrine_Manager::connection($options['connection']);
if(empty($options['directory']))
$dir = './models';
else
$dir = $options['directory'];
Doctrine::loadModels(realpath($dir));
return $manager;
}
}
As far as auto-loading is concerned, you can actually use the Doctrine loader with the new Zend_Loader_Autoloader stack quite easily. Take a look at this page, especially where it mentions the pushAutoloader() method.
Here's the basic run down, though:
$autoloader = Zend_Loader_Autoloader->getInstance();
$autoloader->pushAutoloader(array('Doctrine', 'autoload'), 'Doctrine');
This will use Doctrine's own autoloader for only classes that begin with Doctrine, if they are not already found by other autoloaders in the stack.
Hope this helps a bit.
http://weierophinney.net/matthew/archives/220-Autoloading-Doctrine-and-Doctrine-entities-from-Zend-Framework.html
take a look at this post. It gives a detailed explanation, directory structure and how to use autaloading features.