Search code examples
doctrine-ormzend-framework2doctrine-odmzfdoctrine

example working config for Doctrine ODM zf2 Module?


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


Solution

  • 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'
                    )
                )
            )
        )