2016-04-09 82 views
1

當我想從兩個數據庫中生成實體原則和zend 2我得到這個錯誤:config/autoload/local.php: 我有這個錯誤:致命錯誤:未捕獲的異常'Zend Stdlib Exception BadMethodCallException

Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for doctrine.entitymanager.orm_alternative on line 122:

線122:我有此$entityManager = $this->getServiceLocator() ->get('doctrine.entitymanager.orm_alternative');

return array(
'doctrine' => array(
    'connection' => array(
     // default connection name 
     'orm_default' => array(
      'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver', 
      'params' => array(
       'host'  => 'localhost', 
       'port'  => '3306', 
       'user'  => 'root', 
       'password' => '', 
       'dbname' => 'data1', 
       'charset' => 'utf8', 
       'driverOptions' => array(
         1002=>'SET NAMES utf8' 
       ), 
      ), 

       // Alternative DB connection 
       'orm_alternative' => array(
         'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver', 
         'params' => array(
           'host'  => 'localhost', 
           'port'  => '3306', 
           'user'  => 'root', 
           'password' => '', 
           'dbname' => 'data2', 
           'charset' => 'utf8', 
           'driverOptions' => array(
             1002=>'SET NAMES utf8' 
             ), 
         ), 
       ), 

       // Entity Manager instantiation settings 
       'entitymanager' => array(
         'orm_default' => array(
           'connection' => 'orm_default', 
           'configuration' => 'orm_default', 
         ), 
         'orm_alternative' => array(
           'connection' => 'orm_alternative', 
           'configuration' => 'orm_alternative', 
         ), 
       ), 

Fatal error: Uncaught exception 'Zend\Stdlib\Exception\BadMethodCallException' with message 'The option "orm_al ternative" does not have a callable "setOrmAlternative" ("setormalternative") setter method which must be defin ed' in C:\wamp\www\mp\vendor\zendframework\zend-servicemanager\src\ServiceManager.php on line 943

Zend\ServiceManager\Exception\ServiceNotCreatedException: An abstract factory could not create an instance of d octrine.entitymanager.ormdefault(alias: doctrine.entitymanager.orm_default). in C:\wamp\www\mp\vendor\z endframework\zend-servicemanager\src\ServiceManager.php on line 1132

Zend\ServiceManager\Exception\ServiceNotCreatedException: An exception was raised while creating "Router"; no i nstance returned in C:\wamp\www\mp\vendor\zendframework\zend-servicemanager\src\ServiceManager.php on l ine 943

我怎樣才能解決這個問題呢?

回答

0

服務管理器生成這個愚蠢的錯誤,因爲好像你不相信結構良好,正確indentedreadable代碼。

答案很簡單:配置不正確。問題是不正確的零件不容易檢測到,因爲代碼不可讀。

嘗試下面的配置,其校正並縮進逐行手工:

<?php 
return array(
    'doctrine' => array(
     'connection' => array(
      // default connection name 
      'orm_default' => array(
       'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver', 
       'params' => array(
        'host'   => 'localhost', 
        'port'   => '3306', 
        'user'   => 'root', 
        'password'  => '', 
        'dbname'  => 'data1', 
        'charset'  => 'utf8', 
        'driverOptions' => array(
        1002   =>'SET NAMES utf8' 
        ), 
       ), 
      ), 
      // Alternative DB connection 
      'orm_alternative' => array(
       'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver', 
       'params' => array(
        'host'   => 'localhost', 
        'port'   => '3306', 
        'user'   => 'root', 
        'password'  => '', 
        'dbname'  => 'data2', 
        'charset'  => 'utf8', 
        'driverOptions' => array(
        1002   => 'SET NAMES utf8' 
        ), 
       ), 
      ), 
     ), 

     // Entity Manager instantiation settings 
     'entitymanager' => array(
      'orm_default' => array(
       'connection' => 'orm_default', 
       'configuration' => 'orm_default', 
      ), 
      'orm_alternative' => array(
       'connection' => 'orm_alternative', 
       'configuration' => 'orm_alternative', 
      ), 
     ), 
    ), 

良好縮進高度提高了可讀性。可讀性提高了整體軟件質量,並使您的代碼在邏輯上易於遵循,適合您和其他開發人員。試一下。

+0

總是我有這個問題;抽象工廠不能創建doctrine.entitymanager.ormalternative(別名:doctrine.entitymanager.orm_alternative).at行的實例$ entityManager = $ this-> getServiceLocator() \t - > get ( 'doctrine.entitymanager.orm_alternative'); –

相關問題