1
votes

when i want to generate the entity doctrine and zend 2 from two data bases i get this errors:config/autoload/local.php : i have this Error:

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

line 122: i have this $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

and

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

and

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

How can I solve this issue?

1

1 Answers

0
votes

The Service Manager generating that silly errors because seems like you're not believe in well structured, correctly indented and readable code.

The answer is very easy: configuration is incorrect. The problem is incorrect parts are not easily detectable because the code is not readable.

Try the following configuration which corrected and indented line by line by hand:

<?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',
            ),
        ),
    ),

Good indention highly improves the readability. Readability increases overall software quality and makes your code logically easy to follow for you and other developers. Give a try.