2013-06-29 62 views
1

我下面這個教程蒙戈-ODM配置(模塊/全球)在ZF2

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

當得到這個錯誤:

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

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

我可以通過添加此形成於應用程序/配置/ 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' 
      ) 
     ) 
    ) 
) 

你能解釋一下我,這是爲什麼工作?什麼是最好的方式,因爲我需要在不同的模塊odm?在每個module.config.php中定義它需要的地方?

回答

0

玩過一點我配置我設法設置全球 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' 
     ) 
    ) 

正如你所看到的,我已經改變了NAMESPACE嚴格的價值,這使的伎倆。真的不明白,直到ZF2的新命名空間結束。