2016-04-09 10 views
1

エンティティのdoctrineを生成し、2つのデータベースから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

あなたがうまく構造化されているとは思えないので、この愚かなエラーを生成するService Managerは、正しく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 - >取得( 'doctrine.entitymanager.orm_alternative'); –

関連する問題