I pasted the code from the configuration.md file to
module.config.php
'doctrine' => array(
'connection' => array(
'orm_crawler' => array(
'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
'params' => array(
'host' => 'localhost',
'port' => '3306',
'user' => 'root',
'password' => 'root',
'dbname' => 'crawler',
'driverOptions' => array(
1002 => 'SET NAMES utf8'
),
)
)
),
'configuration' => array(
'orm_crawler' => array(
'metadata_cache' => 'array',
'query_cache' => 'array',
'result_cache' => 'array',
'driver' => 'orm_crawler',
'generate_proxies' => true,
'proxy_dir' => 'data/DoctrineORMModule/Proxy',
'proxy_namespace' => 'DoctrineORMModule\Proxy',
'filters' => array()
)
),
'driver' => array(
'Crawler_Driver' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(
__DIR__ . '/../src/Crawler/Entity'
)
),
'orm_crawler' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\DriverChain',
'drivers' => array(
'Crawler\Entity' => 'Crawler_Driver'
)
),
),
'entitymanager' => array(
'orm_crawler' => array(
'connection' => 'orm_crawler',
'configuration' => 'orm_crawler'
)
),
'eventmanager' => array(
'orm_crawler' => array()
),
'sql_logger_collector' => array(
'orm_crawler' => array(),
),
'entity_resolver' => array(
'orm_crawler' => array()
),
),
```
Module.php
public function getServiceConfig()
{
return array(
'factories' => array(
'doctrine.authenticationadapter.orm_crawler' => new \DoctrineModule\Service\Authentication\AdapterFactory('orm_crawler'),
'doctrine.authenticationstorage.orm_crawler' => new \DoctrineModule\Service\Authentication\StorageFactory('orm_crawler'),
'doctrine.authenticationservice.orm_crawler' => new \DoctrineModule\Service\Authentication\AuthenticationServiceFactory('orm_crawler'),
'doctrine.connection.orm_crawler' => new \DoctrineORMModule\Service\DBALConnectionFactory('orm_crawler'),
'doctrine.configuration.orm_crawler' => new \DoctrineORMModule\Service\ConfigurationFactory('orm_crawler'),
'doctrine.entitymanager.orm_crawler' => new \DoctrineORMModule\Service\EntityManagerFactory('orm_crawler'),
'doctrine.driver.orm_crawler' => new \DoctrineModule\Service\DriverFactory('orm_crawler'),
'doctrine.eventmanager.orm_crawler' => new \DoctrineModule\Service\EventManagerFactory('orm_crawler'),
'doctrine.entity_resolver.orm_crawler' => new \DoctrineORMModule\Service\EntityResolverFactory('orm_crawler'),
'doctrine.sql_logger_collector.orm_crawler' => new \DoctrineORMModule\Service\SQLLoggerCollectorFactory('orm_crawler'),
'doctrine.mapping_collector.orm_crawler' => function (\Zend\ServiceManager\ServiceLocatorInterface $sl) {
$em = $sl->get('doctrine.entitymanager.orm_crawler');
return new \DoctrineORMModule\Collector\MappingCollector($em->getMetadataFactory(), 'orm_crawler_mappings');
},
'DoctrineORMModule\Form\Annotation\AnnotationBuilder' => function(\Zend\ServiceManager\ServiceLocatorInterface $sl) {
return new \DoctrineORMModule\Form\Annotation\AnnotationBuilder($sl->get('doctrine.entitymanager.orm_crawler'));
},
),
);
}
I'm getting the following error:
C:\xampp\vhosts\zf2-trade\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php:529
Message:
Zend\Mvc\Controller\PluginManager::get was unable to fetch or create an instance for getServiceManager
What am I doing wrong? Please help.
Regards Matthew
@foozy: this is exactly what I'm looking. With
you can now update or create the database schema.
My question: how to define which entity should be created in which db? Regards Andrea
@edigu answer works perfectly fine but in some cases, it gives "Following error: Zend\ServiceManager\ServiceManager:: get was unable to fetch or create an instance for doctrine.connection.orm_crawle"
So to resolve this we may change in the Entity Manager settings
for refernece check here
Mac, welcome to stackoverflow! You don't need to define custom factories for each connection respectively. DoctrineORMModule already handles this job for us.
When you need the entity managers, get it from service locator instance by using their names in the alias like this:
or
I'm sharing one of my current application's database configuration which currently uses both PostgreSQL and MySQL connections.
You can easily merge this configuration with yours.
Hope it helps.