i create yml entity, generate entity and config multiple connections
config.yml
# Doctrine Configuration
doctrine:
dbal:
default_connection: db1
connections:
db1:
driver: '%database_driver%'
host: '%database_host%'
port: '%database_port%'
dbname: '%database_name%'
user: '%database_user%'
password: '%database_password%'
charset: UTF8
db2:
driver: '%database_driver2%'
host: '%database_host2%'
port: '%database_port2%'
dbname: '%database_name2%'
user: '%database_user2%'
password: '%database_password2%'
charset: UTF8
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
my orm.yml
TestBundle\Entity\Test:
type: entity
table: Test
id:
id:
type: integer
nullable: false
options:
unsigned: true
id: true
fields:
name:
type: string
nullable: false
length: 255
options:
fixed: false
lifecycleCallbacks: { }
after clean cache and generate entities i try run this code (in command controller)
<?php
...
protected function execute(InputInterface $input, OutputInterface $output)
{
$doctrine = $this->getContainer()->get('doctrine')->getManager('db2');
//both methods cant work :( db2_entity_manager not found
$doctrine = $this->getContainer()->get('doctrine.orm.db2_entity_manager');
$test = $doctrine->getRepository('DionisDataBaseBundle:Test');
}
And i have error:
[InvalidArgumentException]
Doctrine ORM Manager named "db2" does not exist.