Skip to content

Commit a0c5716

Browse files
committed
Add connection configuration details
1 parent db37199 commit a0c5716

File tree

1 file changed

+42
-8
lines changed

1 file changed

+42
-8
lines changed

cookbook/doctrine/multiple_entity_managers.rst

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,26 @@ The following configuration code shows how you can configure two entity managers
2323
.. code-block:: yaml
2424
2525
doctrine:
26+
dbal:
27+
default_connection: default
28+
connections:
29+
default:
30+
driver: %database_driver%
31+
host: %database_host%
32+
port: %database_port%
33+
dbname: %database_name%
34+
user: %database_user%
35+
password: %database_password%
36+
charset: UTF8
37+
customer:
38+
driver: %database_driver2%
39+
host: %database_host2%
40+
port: %database_port2%
41+
dbname: %database_name2%
42+
user: %database_user2%
43+
password: %database_password2%
44+
charset: UTF8
45+
2646
orm:
2747
default_entity_manager: default
2848
entity_managers:
@@ -39,11 +59,25 @@ The following configuration code shows how you can configure two entity managers
3959
In this case, you've defined two entity managers and called them ``default``
4060
and ``customer``. The ``default`` entity manager manages entities in the
4161
``AcmeDemoBundle`` and ``AcmeStoreBundle``, while the ``customer`` entity
42-
manager manages entities in the ``AcmeCustomerBundle``.
62+
manager manages entities in the ``AcmeCustomerBundle``. You've also defined
63+
two connections, one for each entity manager.
64+
65+
.. note::
4366

44-
When working with multiple entity managers, you should be explicit about which
45-
entity manager you want. If you *do* omit the entity manager's name when you
46-
update your schema, the default (i.e. ``default``) is used::
67+
When working with multiple connections and entity managers, you should be
68+
explicit about which configuration you want. If you *do* omit the name of
69+
the connection or entity manager, the default (i.e. ``default``) is used.
70+
71+
72+
When working with multiple connections to create your databases::
73+
74+
# Play only with "default" connection
75+
php app/console doctrine:database:create
76+
77+
# Play only with "customer" connection
78+
php app/console doctrine:database:create --connection=customer
79+
80+
When working with multiple entity managers to update your schema::
4781

4882
# Play only with "default" mappings
4983
php app/console doctrine:schema:update --force
@@ -59,10 +93,10 @@ the default entity manager (i.e. ``default``) is returned::
5993
public function indexAction()
6094
{
6195
// both return the "default" em
62-
$em = $this->get('doctrine')->getEntityManager();
63-
$em = $this->get('doctrine')->getEntityManager('default');
64-
65-
$customerEm = $this->get('doctrine')->getEntityManager('customer');
96+
$em = $this->get('doctrine')->getManager();
97+
$em = $this->get('doctrine')->getManager('default');
98+
99+
$customerEm = $this->get('doctrine')->getManager('customer');
66100
}
67101
}
68102

0 commit comments

Comments
 (0)