几周前我为 Doctrine 和 Zend Framework 编写了一个 Resource Bootstrapper 并将其全部变成了一个小型包装框架,因为我认为 ZF 和 Doctrine 是一个很棒的团队。您可以在此处阅读文章:http:
//coffeecoders.de/2009/06/using-the-zend-framework-18-bootstrapper-and-doctrine-110/
它可以通过 Bootstrap 资源配置完全配置(也包括示例)。不幸的是,Doctrine 在模型文件夹中搜索具有与文件名相同的类名(与 ZF 命名方案不匹配)的模型,因此实际上不可能摆脱注册 Doctrine Autoloader。资源加载器如下所示:
<?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;
}
}