当我想从两个数据库生成实体理论和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',
),
),致命错误:带有消息'The选项“"orm_al ternative”的未命名异常C:\wamp\www\mp\vendor\zendframework\zend-servicemanager\src\ServiceManager.php没有可调用的"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\ endframework\zend-servicemanager\src\ServiceManager.php上的第1132行
和
Zend\ServiceManager\Exception\ServiceNotCreatedException:在创建“路由器”时引发异常;在l 943上的C:\wamp\www\mp\vendor\zendframework\zend-servicemanager\src\ServiceManager.php中没有返回
我怎样才能解决这个问题?
发布于 2016-04-09 23:08:40
服务管理器生成这种愚蠢的错误,因为您似乎不相信结构良好、正确的缩进和可读性代码。
答案很简单:配置不正确。问题是不正确的部分很难被发现,因为代码是不可读的。
尝试以下配置,手动逐行更正和缩进:
<?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',
),
),
),良好的缩进大大提高了可读性。可读性提高了软件的整体质量,使您的代码在逻辑上更容易为您和其他开发人员遵循。试试看。
https://stackoverflow.com/questions/36519226
复制相似问题