整合教条与Zend Framework 1.8应用程序 [英] Integrate Doctrine with Zend Framework 1.8 app

查看:82
本文介绍了整合教条与Zend Framework 1.8应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有兴趣将Doctrine作为ORM用于我正在撰写的新Zend Framework应用程序。我试图找出尽可能简单的整合方式。我发现的每一个例子都是不同的,很多都是ZF 1.8中新增的自动加载功能。没有人为我工作。

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. Every example I find is different, and a lot of them pre-date the new autoloading features in ZF 1.8. None of them have worked for me yet.

有没有人有这样做的好办法?我倾向于将其放在我的引导文件中,但有些人建议使用Zend_Application_Resource插件。困难的部分似乎正在使得Doctrine命名空间和模型类的加载路径正常工作,默认情况下不会遵循Zend自动加载约定。

Does anyone have a good way to do this? I'm inclined to want to place it in my bootstrap file, but some people suggest making a Zend_Application_Resource plugin. The hard part seems to be getting the load paths working correctly for both the Doctrine namespace and the model classes which by default don't follow the Zend auto-loading convention.

有什么想法吗?谢谢。

推荐答案

我在几个星期前为Doctrine和Zend Framework编写了一个资源引导程序,并将其全部变成一个小的包装框架因为我认为ZF和Doctrine是一个伟大的团队。
您可以在这里阅读文章:
http://coffeecoders.de/2009/06/using-the-zend-framework-18-bootstrapper-and-doctrine-110/

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/

它可以通过引导资源配置(也包括示例)完全配置。不幸的是,Doctrine在模型文件夹中搜索与文件名相同的类名(与ZF命名方案不匹配)的模型,因此实际上不可能摆脱注册Doctrine Autoloader。
资源Loader看起来像这样:

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;
    }
}

这篇关于整合教条与Zend Framework 1.8应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆