8000 usage of a non-default entity manager in an entity user provider · symfony/symfony-docs@9eb9117 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9eb9117

Browse files
committed
usage of a non-default entity manager in an entity user provider
The cookbook on entity user providers for the Security component only describes how to create an entity provider using the default entity manager. This may not be sufficient enough if you have multiple entity managers and therefore be eplicit with the entity manager to use in the user provider.
1 parent 1b695b5 commit 9eb9117

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

cookbook/security/entity_provider.rst

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,69 @@ entity user provider to load User entity objects from the database by using
358358
the ``username`` unique field. In other words, this tells Symfony how to
359359
fetch the user from the database before checking the password validity.
360360

361+
.. note::
362+
363+
By default, the entity provider uses the default entity manager to fetch
364+
user information from the database. If you,
365+
:doc:`use multiple entity managers </cookbook/doctrine/multiple_entity_managers>`,
366+
you can specify which manager to use with the ``manager_name`` option:
367+
368+
.. configuration-block::
369+
370+
.. code-block:: yaml
371+
372+
# app/config/config.yml
373+
security:
374+
# ...
375+
376+
providers:
377+
administrators:
378+
entity:
379+
class: AcmeUserBundle:User
380+
property: username
381+
manager_name: customer
382+
383+
# ...
384+
385+
.. code-block:: xml
386+
387+
<!-- app/config/config.xml -->
388+
<?xml version="1.0" encoding="UTF-8"?>
389+
<srv:container xmlns="http://symfony.com/schema/dic/security"
390+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
391+
xmlns:srv="http://symfony.com/schema/dic/services"
392+
xsi:schemaLocation="http://symfony.com/schema/dic/services
393+
http://symfony.com/schema/dic/services/services-1.0.xsd">
394+
<config>
395+
<!-- ... -->
396+
397+
<provider name="administrators">
398+
<entity class="AcmeUserBundle:User"
399+
property="username"
400+
manager-name="customer" />
401+
</provider>
402+
403+
<!-- ... -->
404+
</config>
405+
</srv:container>
406+
407+
.. code-block:: php
408+
409+
// app/config/config.php
410+
$container->loadFromExtension('security', array(
411+
// ...
412+
'providers' => array(
413+
'administrator' => array(
414+
'entity' => array(
415+
'class' => 'AcmeUserBundle:User',
416+
'property' => 'username',
417+
'manager_name' => 'customer',
418+
),
419+
),
420+
),
421+
// ...
422+
));
423+
361424
Forbid inactive Users
362425
---------------------
363426

0 commit comments

Comments
 (0)
0