title: Change database (em) with selector in Symfony 2 using multiple entity managers
body: <p>I am wondering how to use two database connections (entity managers) in my application in symfony 2 and I have read how to work with multiple entity managers (<a href="http://symfony.com/doc/current/cookbook/doctrine/multiple_entity_managers.html" rel="nofollow">http://symfony.com/doc/current/cookbook/doctrine/multiple_entity_managers.html</a>). </p>
  
  <p>In my case I would like to use two databases db2014 and db2015 that can allow to change with a select (combobox) and then change the default entity manager. With this configuration:</p>
  
  <pre><code>doctrine:
      dbal:
          default_connection: default
          connections:
              //connection for db2014
              default:
                  driver:   "%database_driver%"
                  host:     "%database_host%"
                  port:     "%database_port%"
                  dbname:   "%database_name%"
                  user:     "%database_user%"
                  password: "%database_password%"
                  charset:  UTF8
  
              //connection for db2015
              db2015:
                  driver:   "%database_driver2%"
                  host:     "%database_host2%"
                  port:     "%database_port2%"
                  dbname:   "%database_name2%"
                  user:     "%database_user2%"
                  password: "%database_password2%"
                  charset:  UTF8
  </code></pre>
  
  <p>I have understood this article but the main problem is that I must change the code controller to select the entity manager like this:</p>
  
  <pre><code>// All three return the "default/db2014" entity manager
  $em = $this-&gt;get('doctrine')-&gt;getManager();
  
  // Both of these return the "db2015" entity manager
  $db2015Em = $this-&gt;get('doctrine')-&gt;getManager('db2015');
  </code></pre>
  
  <p>Can I set the default entity manager to don't change the controller code? or some ideas to how can i achieve it? I hope to explain well because my english is not very good.</p>
  
  <p>Thanks in advance!</p>