example working config for Doctrine ODM zf2 Module?

4k views Asked by At

can anyone please provide an example of driver configuration for reading annotation of documents in Application/src/Application/Document/.... created this but still doctrine-module odm:schema:create said all collection created but there is no collection in my db

    <?php

return array(
    'doctrine' => array(
        'connection' => array(
            'odm_default' => array(
                'server' => 'localhost',
                'port' => '27017',
//                'user'      => null,
//                'password'  => null,
                'dbname' => 'yehja',
//                'options'   => array()
            ),
        ),
        'configuration' => array(
            'odm_default' => array(
//                'metadata_cache'     => 'array',
//
//                'driver'             => 'odm_default',
//
//                'generate_proxies'   => true,
//                'proxy_dir'          => 'data',
//                'proxy_namespace'    => 'DoctrineMongoODMModule\Proxy',
//
//                'generate_hydrators' => true,
//                'hydrator_dir'       => 'data',
//                'hydrator_namespace' => 'DoctrineMongoODMModule\Hydrator',
//
//                'default_db'         => null,
//
//                'filters'            => array()  // array('filterName' => 'BSON\Filter\Class')
            )
   // /   // ),
    //    'driver' => array(
    //        'odm_default' => array(
    //        //   'drivers' => array('Appl   
   //         )
        ),
        'driver' => array(
            'class' => 'Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver',
            'namespace' => 'Application\Document',
            'paths' => array('module/Application/src/Application/Document'),
        ),
        'documentmanager' => array(
            'odm_default' => array(
//                'connection'    => 'odm_default',
//                'configuration' => 'odm_default',
//                'eventmanager' => 'odm_default'
            )
        ),
        'eventmanager' => array(
            'odm_default' => array(
                'subscribers' => array()
            )
        ),
    ),
);```

module that im using -> https://github.com/doctrine/DoctrineMongoODMModule

2

There are 2 answers

0
Sina Miandashti On BEST ANSWER

these works :

file : config/ autoload/ module.doctrine-mongo-odm.local.php

<?php


Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver::registerAnnotationClasses();
return array(
    'doctrine' => array(
        'connection' => array(
            'odm_default' => array(
                'server' => 'localhost',
                'port' => '27017',
//                'user'      => null,
//                'password'  => null,
                'dbname' => 'yehja',
//                'options'   => array()
            ),
        ),

        'configuration' => array(
            'odm_default' => array(
//                'metadata_cache'     => 'array',
//
//                'driver'             => 'odm_default',
//
//                'generate_proxies'   => true,
//                'proxy_dir'          => 'data',
//                'proxy_namespace'    => 'DoctrineMongoODMModule\Proxy',
//
//                'generate_hydrators' => true,
//                'hydrator_dir'       => 'data',
//                'hydrator_namespace' => 'DoctrineMongoODMModule\Hydrator',
//
//                'default_db'         => null,
//
//                'filters'            => array()  // array('filterName' => 'BSON\Filter\Class')
            )
   // /   // ),
    //    'driver' => array(
    //        'odm_default' => array(
    //        //   'drivers' => array('Appl   
   //         )
        ),

        'documentmanager' => array(
            'odm_default' => array(
//                'connection'    => 'odm_default',
//                'configuration' => 'odm_default',
//                'eventmanager' => 'odm_default'
            )
        ),
        'eventmanager' => array(
            'odm_default' => array(
                'subscribers' => array()
            )
        ),
    ),
);

and file : module/ Application/ config/ module.config.php add these lines

'doctrine' => array(
        'driver' => array(
            __NAMESPACE__ . '_driver' => array(
                'class' => 'Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver',

                'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Document')
            ),
            'odm_default' => array(
                'drivers' => array(
                    __NAMESPACE__ . '\Document' => __NAMESPACE__ . '_driver'
                )
            )
        )
    )
1
jhuet On

I guess you got the config idea from this question but the format changed since then. Here's one i have (dibber being the name of the app - and yes it's PHP 5.4 arrays) :

'driver' => [
    'dibber' => [
        'class' => 'Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver',
    ],
    'odm_default' => [
        'drivers' => [
            'Dibber\Document' => 'dibber'
        ]
    ]
],

This basically means that Dibber\Document is the namespace in wich the annotation driver is going to be used. So for you it would be Application\Document.