简体   繁体   English

zf2中的mongo-odm配置(模块/全局)

[英]mongo-odm configuration (module / global) in zf2

I was following this tutorial 我正在关注本教程

http://www.bigwisu.com/2012/10/03/zend-framework-2-doctrine-odm http://www.bigwisu.com/2012/10/03/zend-framework-2-doctrine-odm

when a get this error: 当得到这个错误:

The class 'Application\Document\User' was not found in the chain configured namespaces 

This is my module.doctrine-mongo-odm.local.php after a little bit of testing: 经过一点测试,这是我的module.doctrine-mongo-odm.local.php:

<?php
return array(
    'doctrine' => array(

        'connection' => array(
            'odm_default' => array(
                'server'    => 'localhost',
                'port'      => '27017',
                'user'      => '',
                'password'  => '',
                'dbname'    => 'test',
                'options'   => array()
            ),
        ),

        'configuration' => array(
            'odm_default' => array(
                'metadata_cache'     => 'array',
                'driver'             => 'odm_default',
                'generate_proxies'   => true,
                'proxy_dir'          => 'data/DoctrineMongoODMModule/Proxy',
                'proxy_namespace'    => 'DoctrineMongoODMModule\Proxy',

                'generate_hydrators' => true,
                'hydrator_dir'       => 'data/DoctrineMongoODMModule/Hydrator',
                'hydrator_namespace' => 'DoctrineMongoODMModule\Hydrator',

                'default_db'         => 'test',

                'filters'            => array(),  // array('filterName' => 'BSON\Filter\Class'),

                'logger'             => null // 'DoctrineMongoODMModule\Logging\DebugStack'
            )
        ),

        'odm_default' => array(
            'drivers' => array(
                'Application\Document' => 'odm_driver'
            )
        ),

        'odm_driver' => array(
            'class' => 'Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver',
            'cache' => 'array',
            '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()
            )
        ),
    ),
);

I could fix the error by adding this information to the the Application/config/module.config.php and remove it from the global conf: 我可以通过将以下信息添加到Application / config / module.config.php并将其从全局conf中删除来解决该错误:

<?php
namespace Application;
return array(
// routes, etc
'doctrine' => array(
    'driver' => array(
        'odm_driver' => array(
            'class' => 'Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver',
            'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Document')
        ),
        'odm_default' => array(
            'drivers' => array(
                __NAMESPACE__ . '\Document' => 'odm_driver'
            )
        )
    )
)

Can you explain me, why this is working? 您能解释一下,为什么这样吗? And what is the best way to go, since i need the odm in different modules? 既然我需要在不同模块中使用odm,那么最好的方法是什么? Define it in every module.config.php where its needed? 在需要它的每个module.config.php中定义它?

Played a little with the configs I managed to setup Global configruation. 在我设法设置全局配置的配置上玩了一点。

    'odm_driver' => array(
        'class' => 'Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver',
        'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Document')
    ),
    'odm_default' => array(
        'drivers' => array(
Change is here --> 'Admin\Document' => 'odm_driver'
        )
    )  

As you can see, I've changed NAMESPACE to strict value, this made the trick. 如您所见,我已将NAMESPACE更改为严格值,这很容易。 Really don't understand till the end new Namespaces in the ZF2. 真的不了解ZF2中的新命名空间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM