multiple connections with doctrine in symfony 2.3

2019-05-19 03:06发布

问题:

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.

this was before :

# 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

and it was working fine

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

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 ;) )

EDIT

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: AppBundle\Entity
            alias: App
        DbBccCrawlBundle:
            type: annotation
            dir: '%kernel.root_dir%/../src/DbBccCrawlBundle/Entity'
            prefix: DbBccCrawlBundle\Entity
            alias: Crawl

still doesn't work....

EDIT 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

not working either

回答1:

I donno why/how but it works

here's the code :

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

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.

Thanks anyway

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