8000 minor #4023 [Cookbook][Security] usage of a non-default entity manage… · symfony/symfony-docs@f95bbf3 · GitHub
[go: up one dir, main page]

Skip to content

Commit f95bbf3

Browse files
committed
minor #4023 [Cookbook][Security] usage of a non-default entity manager in an entity user provider (xabbuh)
This PR was merged into the 2.3 branch. Discussion ---------- [Cookbook][Security] usage of a non-default entity manager in an entity user provider | Q | A | ------------- | --- | Doc fix? | yes | New docs? | no | Applies to | all | Fixed tickets | #4021 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. Commits ------- 9eb9117 usage of a non-default entity manager in an entity user provider
2 parents 27b1003 + 9eb9117 commit f95bbf3

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
@@ -364,6 +364,69 @@ entity user provider to load User entity objects from the database by using
364364
the ``username`` unique field. In other words, this tells Symfony how to
365365
fetch the user from the database before checking the password validity.
366366

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

0 commit comments

Comments
 (0)
0