Symfony 2.3中使用Doctrine进行多个连接

3
我正在尝试在我的Symfony项目中使用Doctrine进行多连接。
首先,我只使用一个数据库,然后我需要添加另一个数据库。
这是之前的情况:
# Doctrine Configuration
doctrine:
  dbal:
    default_connection: extranet
    connections:
        extranet:
            driver:   pdo_mysql
            host:     "%db_extranet_host%"
            port:     "%db_extranet_port%"
            dbname:   "%db_extranet_name%"
            user:     "%db_extranet_user%"
            password: "%db_extranet_password%"
            charset:  UTF8
orm:
    auto_generate_proxy_classes: "%kernel.debug%"
    entity_managers:
        extranet:
            naming_strategy: doctrine.orm.naming_strategy.underscore
            auto_mapping: true

"然后它运行得很好。接着我添加了“爬行”数据库:"
# Doctrine Configuration
doctrine:
  dbal:
    default_connection: extranet
    connections:
        extranet:
            driver:   pdo_mysql
            host:     "%db_extranet_host%"
            port:     "%db_extranet_port%"
            dbname:   "%db_extranet_name%"
            user:     "%db_extranet_user%"
            password: "%db_extranet_password%"
            charset:  UTF8
        crawl:
            driver:   pdo_mysql
            host:     "%db_crawl_host%"
            port:     "%db_crawl_port%"
            dbname:   "%db_crawl_name%"
            user:     "%db_crawl_user%"
            password: "%db_crawl_password%"
            charset:  UTF8
orm:
    auto_generate_proxy_classes: "%kernel.debug%"
    default_entity_manager: extranet
    entity_managers:
        extranet:
            connection: extranet
            naming_strategy: doctrine.orm.naming_strategy.underscore
            mappings:
                AppBundle: ~
        crawl:
            connection: crawl
            naming_strategy: doctrine.orm.naming_strategy.underscore
            mappings:
                DbBccCrawlBundle: ~

我取消了自动映射并添加了一些东西,但是现在我失去了与外部网络的连接(例如,用户无法再登录)。有任何想法吗?(如果你读到这里,谢谢;))
编辑:按照http://symfony.com/doc/2.3/reference/configuration/doctrine.html#mapping-entities-outside-of-a-bundle,我尝试使用相同的语法:
orm:
    # auto_generate_proxy_classes: "%kernel.debug%"
    default_entity_manager: extranet
    # auto_mapping: true
    mappings:
        AppBundle:
            type: annotation
            dir: '%kernel.root_dir%/../src/AppBundle/Entity'
            prefix: AppBundle\Entity
            alias: App
        DbBccCrawlBundle:
            type: annotation
            dir: '%kernel.root_dir%/../src/DbBccCrawlBundle/Entity'
            prefix: DbBccCrawlBundle\Entity
            alias: Crawl

仍然无法工作....

编辑2

orm:
    auto_generate_proxy_classes: "%kernel.debug%"
    default_entity_manager: extranet
    entity_managers:
        auto_mapping: true
        extranet:
            connection: extranet
            naming_strategy: doctrine.orm.naming_strategy.underscore
            mappings:
                AppBundle:
                    type:   annotation
                    # dir:    '%kernel.root_dir%/../src/AppBundle/Entity'
                    # prefix: AppBundle\Entity
                    alias:  App
        crawl:
            connection: crawl
            naming_strategy: doctrine.orm.naming_strategy.underscore
            mappings:
                DbBccCrawlBundle:
                    type:   annotation
                    # dir:    '%kernel.root_dir%/../src/DbBccCrawlBundle/Entity'
                    # prefix: DbBccCrawlBundle\Entity
                    alias:  Crawl

也不起作用


是的,我已经读了几遍了。我使用Web服务来进行大部分查询,但我需要一个存储一些重复信息的表格... - Fire Frost
好的,在“映射捆绑外实体”部分尝试了相同的语法/格式,但仍然无法连接... - Fire Frost
我正在确认我指向正确的实体,问题可能就在那里... $em = $this->get('doctrine')->getEntityManager('default'); $em = $this->get('doctrine')->getEntityManager('another'); - Fire Frost
你尝试过这个吗?$this->get('doctrine')->getEntityManager();或者$this->get('doctrine')->getEntityManager('extranet'); - Sebastian
也许你需要查看https://dev59.com/0aDia4cB1Zd3GeqPCVyw#43042335。 - Maulik Savaliya
显示剩余5条评论
1个回答

2
我不知道为什么/如何,但这个代码可以运行。
以下是代码:
orm:
    auto_generate_proxy_classes: "%kernel.debug%"
    entity_managers:
        extranet:
            naming_strategy: doctrine.orm.naming_strategy.underscore
            auto_mapping: true
        crawl:
            naming_strategy: doctrine.orm.naming_strategy.underscore
            connection: crawl
            mappings:
                DbBccCrawlBundle: ~

事实上,我在开始时尝试过这个方法,但失败了(类X未找到...)。如果有人能够解释一下,我将非常乐意阅读。无论如何感谢您。这是问题的第二部分,以下是开头:在尝试使用Doctrine进行多连接时,“X”类未在配置的命名空间链中找到

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接