douzuizhuo0587
2016-06-23 13:35
采纳率: 0%
浏览 66
已采纳

名为“db2”的Symfony2 Doctrine ORM Manager不存在

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.

图片转代码服务由CSDN问答提供 功能建议

我创建yml实体,生成实体并配置多个连接

config。 yml

  #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  
   
 
 

我的orm.yml

  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:{} 
   
 
 

清理缓存并生成实体后我尝试运行此代码(在命令控制器中)< / 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'); 
 
} 
    
 
 

我有错误:

[InvalidArgument 例外]
名称为“db2”的Doctrine ORM Manager不存在。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题