2017-05-04 105 views
0

我在zf3中使用了doctrine2,而連接多個數據庫導致錯誤。 然後下面是我在global.phpdoctrine2多個數據庫連接在ZF3?

return [ 
    'doctrine' => [ 
     'connection' => [ 
      'orm_default' => [ 
       'driverClass' => PDOMySqlDriver::class, 
       'params' => [ 
        'host'  => '127.0.0.1', 
        'user'  => 'root', 
        'password' => '123456', 
        'dbname' => 'zf3.com', 
        'charset' => 'utf8', 
       ] 
      ], 
      'orm_passport' => [ 
       'driverClass' => PDOMySqlDriver::class, 
       'params' => [ 
        'host'  => '127.0.0.1', 
        'user'  => 'root', 
        'password' => '123456', 
        'dbname' => 'zf3.com.passport', 
        'charset' => 'utf8', 
       ] 
      ], 
     ], 
     'entitymanager' => [ 
      'orm_passport' => [ 
       'connection' => 'orm_passport', 
      ] 
     ], 
    ], 
]; 

和驅動程序的配置在module.config.php配置如下:

'doctrine' => [ 
     'driver' => [ 
      __NAMESPACE__ . '_driver' => [ 
       'class' => AnnotationDriver::class, 
       'cache' => 'array', 
       'paths' => [__DIR__ . '/../src/Entity'] 
      ], 
      'orm_passport' => [ 
       'drivers' => [ 
        __NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_driver' 
       ] 
      ] 
     ] 
    ], 

在我IndexController.php

public function indexAction() 
    { 
     // Get recent users 
     $users = $this->entityManager->getRepository(Users::class) 
      ->findBy(['status'=>Users::ACTIVE_STATUS_NO],['timeCreated'=>'DESC']); 

     //\Doctrine\Common\Util\Debug::dump($users); 

     return new ViewModel([ 
      'users' => $users 
     ]); 
    } 

錯誤消息: 未在鏈配置的命名空間中找到類「Passport \ Entity \ Users」Application \ Entity

+0

其中namespace是'module.config.php'文件的內容嗎? '應用程序','護照'? – gsc

+0

我改變我的global.php,添加一些選擇,它的工作原理 –

回答

0

,以下是我global.php

return [ 
    'doctrine' => [ 
     'connection' => [ 
      'orm_default' => [ 
       'driverClass' => PDOMySqlDriver::class, 
       'params' => [ 
        'host'  => '127.0.0.1', 
        'user'  => 'root', 
        'password' => '123456', 
        'dbname' => 'zf3.com', 
        'charset' => 'utf8', 
       ] 
      ], 
      'orm_passport' => [ 
       'driverClass' => PDOMySqlDriver::class, 
       'params' => [ 
        'host'  => '127.0.0.1', 
        'user'  => 'root', 
        'password' => '123456', 
        'dbname' => 'zf3.com.passport', 
        'charset' => 'utf8', 
       ] 
      ], 
     ], 
     'entitymanager' => [ 
      'orm_passport' => [ 
       'connection' => 'orm_passport', 
       'configuration' => 'orm_passport', 
      ] 
     ], 
     'migrations_configuration' => [ 
      'orm_passport' => [ 
       'directory' => 'data/DoctrineORMModule/Migrations', 
       'name' => 'Doctrine Database Migrations', 
       'namespace' => 'DoctrineORMModule\\Migrations', 
       'table' => 'migrations', 
       'column' => 'version', 
      ], 
     ], 
     'configuration' => [ 
      'orm_passport' => [ 
       'metadata_cache' => 'array', 
       'query_cache' => 'array', 
       'result_cache' => 'array', 
       'hydration_cache' => 'array', 
       'driver' => 'orm_passport', 
       'generate_proxies' => true, 
       'proxy_dir' => 'data/DoctrineORMModule/Proxy', 
       'proxy_namespace' => 'DoctrineORMModule\\Proxy', 
      ] 
     ], 
     'authentication' => [ 
      'odm_passport' => [], 
      'orm_passport' => [ 
       'objectManager' => 'doctrine.entitymanager.orm_passport', 
      ], 
     ], 
     'authenticationadapter' => [ 
      'odm_passport' => true, 
      'orm_passport' => true, 
     ], 
     'authenticationstorage' => [ 
      'odm_passport' => true, 
      'orm_passport' => true, 
     ], 
     'authenticationservice' => [ 
      'odm_passport' => true, 
      'orm_passport' => true, 
     ], 
    ], 
]; 

它的作品!