2
votes

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
There may be a few people here understanding that question, but i don't. Could you provide some code that you have tried? Maybe then i'd get an understanding of your concern. The ObjectManager can be fetched via $this->getServiceLocator()->get('Doctrine\ORM\EntityManager');Sam
Sorry... Maybe i wasn't so clear in my question. I want to use the PersistentObject that is in Doctrine, therefore I must set the objectManger with the setObjectManager in the PersistentObject class. I don't want to do that in every Entity but I want to do that once. Therefore I must call the PersistentObject::setObjectManager somewhere in my code. But I don't know where to do it... I hope I'ts a bit clearer to you now!Paul Oostenrijk
You need to specify which version of Zend Framework 1 or 2 and also which version of Doctrine you are trying to implement wouldn't hurt.RockyFord
I'm very sorry. It is ZendFramework 2 and Doctrine 2. But @timdev gave me the correct answer. Thanks for your time guys. I try my best to be clearer next time!Paul Oostenrijk

1 Answers

3
votes

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

}