给我你的怀抱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處理。