当我想从两个数据库生成实体doctrine和zend 2时,我得到这个错误:config / autoload / local.php: 我有这个错误:
Zend \ ServiceManager \ ServiceManager :: get无法获取或创建 第122行的doctrine.entitymanager.orm_alternative实例:
第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',
),
),
致命错误:未捕获的异常'Zend \ Stdlib \ Exception \ BadMethodCallException',消息'选项'orm_al ternative“没有可调用的”setOrmAlternative“(”setormalternative“)setter方法,必须定义 第943行的C:\ wamp \ www \ mp \ vendor \ zendframework \ zend-servicemanager \ src \ ServiceManager.php
和
Zend \ ServiceManager \ Exception \ ServiceNotCreatedException:抽象工厂无法创建d的实例 octrine.entitymanager.ormdefault(别名:doctrine.entitymanager.orm_default)。在C:\ wamp \ www \ mp \ vendor \ z中 第1132行的endframework \ zend-servicemanager \ src \ ServiceManager.php
和
Zend \ ServiceManager \ Exception \ ServiceNotCreatedException:创建“路由器”时引发异常;不,我 nstance在C:\ wamp \ www \ mp \ vendor \ zendframework \ zend-servicemanager \ src \ ServiceManager.php中返回 ine 943
我该如何解决这个问题?
答案 0 :(得分:0)
Service Manager会产生这些愚蠢的错误,因为您似乎不相信结构良好,正确的indented和readable代码。
答案很简单:配置不正确。问题是不正确的部件不易检测,因为代码不可读。
尝试以下配置,逐行修正和缩进:
<?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',
),
),
),
良好的凹痕极大地提高了可读性。可读性提高了整体软件质量,使您和其他开发人员在逻辑上易于遵循您的代码。试一试。