symfony 2.3 中与学说的多重联系 [英] multiple connections with doctrine in symfony 2.3

查看:18
本文介绍了symfony 2.3 中与学说的多重联系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我试图在我的 symfony 项目中与教义建立多重联系.

So I'm trying to do a multiple connection with doctrine in my symfony project.

首先,我只使用一个数据库,然后我需要添加另一个.

First, I was only using one database, then I needed to add another.

这是以前的:

# 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

一切正常

然后我添加了抓取"数据库:

THEN I added the "crawl" database :

# 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: ~

我摆脱了 auto_mapping &添加了一些东西

I got rid of the auto_mapping & added few things

但是,现在我失去了与外联网的连接(例如,用户无法再登录)

BUT, now I lost connection to extranet (users can't loggin anymore for example)

有什么想法吗?(如果你读到那么远,谢谢;))

Any ideas? (and thanks if you read that far ;) )

编辑

遵循 http://symfony.com/doc/2.3/reference/configuration/doctrine.html#mapping-entities-outside-of-a-bundle 我尝试使用相同的语法:

following http://symfony.com/doc/2.3/reference/configuration/doctrine.html#mapping-entities-outside-of-a-bundle I tried to have the same syntax :

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: AppBundleEntity
            alias: App
        DbBccCrawlBundle:
            type: annotation
            dir: '%kernel.root_dir%/../src/DbBccCrawlBundle/Entity'
            prefix: DbBccCrawlBundleEntity
            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: AppBundleEntity
                    alias:  App
        crawl:
            connection: crawl
            naming_strategy: doctrine.orm.naming_strategy.underscore
            mappings:
                DbBccCrawlBundle:
                    type:   annotation
                    # dir:    '%kernel.root_dir%/../src/DbBccCrawlBundle/Entity'
                    # prefix: DbBccCrawlBundleEntity
                    alias:  Crawl

也不行

推荐答案

我不知道为什么/如何,但它有效

I donno why/how but it works

代码如下:

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)

the thing is that I tried that at the start and it failed (the class X not found in...)

如果有人有解释,我会非常乐意阅读.

If anyone has an explenation, I'll be more than happy to read it.

还是谢谢

这是问题的第二部分,下面是开始:类在链配置的命名空间中找不到X"...当我尝试与学说进行多重连接时

This was the 2nd part of the question, here's the begening : The class 'X' was not found in the chain configured namespaces ... when I try a multiple connection with doctrine

这篇关于symfony 2.3 中与学说的多重联系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆