Doctrine ODM zf2模块的示例工作配置?

时间:2012-08-18 07:23:35

标签: doctrine-orm zend-framework2 doctrine-odm zfdoctrine

任何人都可以提供一个驱动程序配置示例,用于在Application / src / Application / Document /中读取文档注释。 创造了这个 但仍然是doctrine-module odm:schema:create表示创建了所有集合,但我的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()
            )
        ),
    ),
);```

我正在使用的模块 - &gt; https://github.com/doctrine/DoctrineMongoODMModule

2 个答案:

答案 0 :(得分:3)

这些作品:

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()
            )
        ),
    ),
);

文件:module / Application / config / module.config.php 添加这些行

'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 :(得分:1)

我猜你从this question得到了配置的想法,但从那时起格式发生了变化。这是我的一个(dibber是应用程序的名称 - 是的它是PHP 5.4阵列):

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

这基本上意味着Dibber\Document是将使用注释驱动程序的命名空间。所以对你而言,它将是Application\Document

相关问题