Using PersistentObject from Doctrine in Zend Framework

China☆狼群 提交于 2019-12-11 01:12:25

问题


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!


回答1:


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

}


来源:https://stackoverflow.com/questions/15842640/using-persistentobject-from-doctrine-in-zend-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!