问题描述:

How can I use different databases in every single bundle of Symfony2 with Doctrine2?

FooBundle <- Database "Foo"

BarBundle <- Database "Bar"

网友答案:

This may help How to work with Multiple Entity Managers and Connections.

So you can define multiple Entity Managers related to your databases connections, you can then map your bundle(s) to the right Entity Manager.

The examples on the documentation are well explained.

doctrine:
    dbal:
        default_connection:   foo_connection
        connections:
            foo_connection:
                # ...
                # Foo connection parameters
                # ...
            bar_connection:
                # ...
                # Bar connection parameters
                # ...

    orm:
        default_entity_manager:   foo_manager
        entity_managers:
            foo_manager:
                connection:        foo_connection
                mappings:
                    FooBundle: ~
            bar_manager:
                connection:       bar_connection
                mappings:
                    BarBundle: ~
相关阅读:
Top