本文介绍了在Zend框架中使用Doctrine的PersistentObject的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题给大家。在我使用Codeigniter大约1年之后,我刚刚开始使用Zend Framework。我已经安装了所有东西,一切都在运行。但我有一个问题。我想用原则来建模。而且我一直使用Doctrine的PersistentObject,但是我似乎无法使它工作。



问题是我需要通过一个ObjectManager到PersistentObject。但我不能让它工作。有谁有任何想法如何通过ObjectManger从DoctrineORM模块到PersistentObject?



如果我不够清楚,可以告诉我。对我说英语有点麻烦。我很抱歉!

解决方案

你可以在Module的onBootstrap()方法中执行此操作:

 <?php 
命名空间MyApplication;
使用Doctrine\Common\Persistence\PersistentObject;

类模块{

public function onBootstrap($ e){
$ serviceManager = $ e-> getApplication() - > getServiceManager();
PersistentObject :: setObjectManager($ sm-> get('Doctrine\ORM\EntityManager');
}

}


I have a question for you all. I'm just starting to use Zend Framework after I have used Codeigniter for about 1 year now. I have installed everything and everything is running now. But I have one problem. I want to use Doctrine for my modelling. And I always used the PersistentObject from Doctrine, but I can't seem to get it working.

The problem is that I need to pass through a ObjectManager to the PersistentObject. But I can't make it work. Does anybody have any idea how I can pass through the ObjectManger from the DoctrineORM module to the PersistentObject?

If I'm not clear enough you can tell me. It's a bit an hassle for me to speak english. I'm sorry about that!

解决方案

You could do it in your Module's onBootstrap() method:

<?php
namespace MyApplication;
use Doctrine\Common\Persistence\PersistentObject;

class Module {

    public function onBootstrap($e){
        $serviceManager = $e->getApplication()->getServiceManager();
        PersistentObject::setObjectManager($sm->get('Doctrine\ORM\EntityManager');
    }

}

这篇关于在Zend框架中使用Doctrine的PersistentObject的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 17:56