你可以这样做:
doctrine:
dbal:
default_connection: alpha
connections:
alpha:
driver: pdo_mysql
host: localhost
dbname: alpha
user: root
charset: UTF8
beta:
driver: pdo_pgsql
host: localhost
dbname: beta
user: root
charset: UTF8
orm:
auto_generate_proxy_classes: %kernel.debug%
entity_managers:
alpha:
connection: alpha
beta:
connection: beta
你看,我们在dbal部分声明了两个连接,在orm one中声明了两个实体管理器.
之后,您可以同时使用:
$emAlpha = $this->getDoctrine()->getEntityManager('alpha');
$emBeta = $this->getDoctrine()->getEntityManager('beta');
由于alpha one被定义为默认值,因此您无需指定其名称即可访问它:
$emAlpha = $this->getDoctrine()->getEntityManager();