给我你的怀抱2017-05-16 16:47:11
先配置多个connection及对应的manager:
doctrine:
dbal:
default_connection: default
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:
default_entity_manager: db1
entity_managers:
db1:
connection: db1
mappings:
UsingDb1Bundle: ~
db2:
connection: db2
mappings:
UsingDb2Bundle: ~
上面的配置是让两个bundle分别使用不同的manager,如果要在一个bundle里使用一个manager,可以:
entity_managers:
db1:
connection: db1
mappings:
db1:
dir: Path/To/EntityFolder1
db2:
connection: db2
mappings:
db2:
dir: Path/To/EntityFolder2
你得把entity分开放在不同的文件夹里。
有了多个manager,使用起来和单个就没区别了,注意把对象交给相应的manager处理。