Zend Framework 1.11 Integration with MongoDB Using Doctrine ODM

Is there any way to integrate the zend framework with Mongo using Doctrine 2 beta ODM? I watched the zendcast ORM integration video for Doctrine 2 for MySQL, but Bisna has never been updated to support Mongo.

I think I can try to hack Bisna to make her work, but I would like to know if anyone else has found a way to make her work.

+4
source share
2 answers

It is very easy to write a Zend Bootstrap Resource .

Here is one of them:

<?php namespace Cob\Application\Resource; use Doctrine\Common\Annotations\AnnotationReader, Doctrine\ODM\MongoDB\DocumentManager, Doctrine\MongoDB\Connection, Doctrine\ODM\MongoDB\Configuration, Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver, Doctrine\Common\EventManager; /** * Creates a MongoDB connection and DocumentManager instance * * @author Andrew Cobby < cobby@cobbweb.me > */ class Mongo extends \Zend_Application_Resource_ResourceAbstract { /** * @return \Doctrine\ODM\MongoDB\DocumentManager */ public function init() { $options = $this->getOptions() + array( 'defaultDB' => 'my_database', 'proxyDir' => APPLICATION_PATH . '/domain/Proxies', 'proxyNamespace' => 'Application\Proxies', 'hydratorDir' => APPLICATION_PATH . '/domain/Hydrators', 'hydratorNamespace' => 'Application\Hydrators' ); $config = new Configuration(); $config->setProxyDir($options['proxyDir']); $config->setProxyNamespace($options['proxyNamespace']); $config->setHydratorDir($options['hydratorDir']); $config->setHydratorNamespace($options['hydratorNamespace']); $config->setDefaultDB($options['defaultDB']); $reader = new AnnotationReader(); $reader->setDefaultAnnotationNamespace('Doctrine\ODM\MongoDB\Mapping\\'); $config->setMetadataDriverImpl(new AnnotationDriver($reader, $this->getDocumentPaths())); $evm = new EventManager(); $evm->addEventSubscriber(new SlugSubscriber()); return DocumentManager::create(new Connection(), $config, $evm); } public function getDocumentPaths() { $paths = array(); foreach(new \DirectoryIterator(APPLICATION_PATH . '/modules') as $module){ $path = $module->getPathname() . '/src/Domain/Document'; if((!$module->isDir() || $module->isDot()) || !is_dir($path)){ continue; } $paths[] = $path; } if(!count($paths)){ throw new \Exception("No document paths found"); } return $paths; } } 

Although you will have to update the getDocumentPaths () method to match the structure of your application directory.

+7
source

I wrote my own very simple application resource plugin and container, using the Guilherme integration kit for inspiration.

I am sure that it can be much more in terms of capturing options, but I decided that I would add them as I need them.

See https://gist.github.com/891415

+1
source

Source: https://habr.com/ru/post/1345565/


All Articles