Multiple dynamic EntityManagers in Symfony2

Symfony2 is fantastic when coupled with Doctrine, but unfortunately Doctrine has its limitations and does not inherently support dynamic EntityManager connections, because the parameters for each connection must be defined and loaded at the kernel level.

This assumes that each of the connections have an identical schema mapped by Doctrine2.

My live implementation functions for a single/multi tenant shared architecture in which connection parameters are encrypted and housed in MasterDatabase, while ChildDatabase1, ChildDatabase2, all have the exact same schema, but isolated data for a variety of business reasons.

There are several components to making this work:

  1. app/config/parameters.yml
  2. app/config/config.yml
  3. app/config/services.yml
  4. MyApp/Services/ApplicationConnector.php





Usage in a Controller