首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >致命错误:未命名异常'Zend\Stdlib\ exception \BadMethodCallException

致命错误:未命名异常'Zend\Stdlib\ exception \BadMethodCallException
EN

Stack Overflow用户
提问于 2016-04-09 16:01:05
回答 1查看 530关注 0票数 1

当我想从两个数据库生成实体理论和zend 2时,我得到以下错误:config/autoload/local.php:我有这个错误:

Zend\ServiceManager\ServiceManager::get无法在第122行中为doctrine.entitymanager.orm_alternative获取或创建实例:

第122行:我有这个$entityManager = $this->getServiceLocator() ->get('doctrine.entitymanager.orm_alternative');

代码语言:javascript
复制
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中没有返回

我怎样才能解决这个问题?

EN

回答 1

Stack Overflow用户

发布于 2016-04-09 23:08:40

服务管理器生成这种愚蠢的错误,因为您似乎不相信结构良好、正确的缩进可读性代码。

答案很简单:配置不正确。问题是不正确的部分很难被发现,因为代码是不可读的。

尝试以下配置,手动逐行更正和缩进:

代码语言:javascript
复制
<?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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36519226

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档