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.

  • 写回答

2条回答 默认 最新

  • douluo6626 2016-06-23 13:52
    关注

    change config.yml to

     orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        default_entity_manager: db1
        entity_managers:
            db1:
                connection: db1
                mappings:
                    DionisDataBaseBundle: ~
            db2:
                connection: db2
                mappings:
                    DionisDataBaseBundle: ~
            db3:
                connection: db2
                mappings:
                    DionisDataBaseBundle: ~
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?