2013-06-29 2 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() 
      ) 
     ), 
    ), 
); 

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

왜 이것이 작동하는지 설명해 주시겠습니까? 그리고 내가 다른 모듈에 odm이 필요하기 때문에 갈 가장 좋은 방법은 무엇입니까? 필요한 모든 module.config.php에서 정의 하시겠습니까?

답변

0

configs로 설정 한 부분을 약간만 재생했습니다. 글로벌 구성으로 설정했습니다. 당신이 볼 수 있듯이

'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의 새로운 네임 스페이스가 끝날 때까지 이해하지 못합니다.