我创建yml实体,生成实体并配置多个连接 p>
config。 yml p>
#Dystrine 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:
驱动程序:'%database_driver2%'
host:'%database_host2%'
port:'%database_port2%'
dbname:'%database_name2%'
user:'%database_user2%'
password:' %database_password2%'
字符集:UTF8
orm:
auto_generate_proxy_classes:“%kernel.debug%”
naming_strategy:doctrine.orm.naming_strategy.underscore
auto_mapping:true
code> pre>
我的orm.yml p>
TestBundle \ Entity \ Test:
type:entity
table:Test \ nid:
id:
type:integer
nullable:false
options:
unsigned:true
id:true
fields:
name:
type:string
nullable:false
length :255
选项:
修复:false
lifecycleCallbacks:{}
code> pre>
清理缓存并生成实体后我尝试运行此代码(在命令控制器中)< / p>
&lt;?php
...
保护函数execute(InputInterface $ input,OutputInterface $ output)
{
$ doctrine = $ this- &gt; getContainer() - &gt; get('doctrine') - &gt; getManager('db2');
//两种方法都无法工作:( db2_entity_manager not found
$ doctrine = $ this-&gt; getContainer() - &gt; get('doctrine.orm.db2_entity_manager');
$ test = $ doctrine-&gt; getRepository('DionisDataBaseBundle:Test');
}
code> pre>
我有错误: p>
[InvalidArgument 例外]
名称为“db2”的Doctrine ORM Manager不存在。 p>
blockquote>
div>