0

I have a hard problem that wants an answear. I am working with Symfony and I installed Sonata to manage the admin area. After I completed to do that, my prompt line give me this error:

This is the error

This is my code:

parameters:

services:       
    app.security.user_login_form_authenticator:
        class: AppBundle\Security\UserLoginFormAuthenticator
        autowire: true

    app.security.admin_login_form_authenticator:
        class: AppBundle\Security\AdminLoginFormAuthenticator
        autowire: true

Please, help me.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Alex Enax
  • 3
  • 1
  • Do you have multiple EntityManger defined in the config file(s) of your project? – Forer Nov 29 '16 at 10:45
  • I think yes. After I instaled Sonata, the prompt line said me the error in the picture https://i.stack.imgur.com/ZrFCL.png – Alex Enax Dec 01 '16 at 08:07

1 Answers1

0

Autowiring feature is handy, but it has a limitations.

As you say, you have multiple instances of entity manager. So, Symfony doesn't know which of them should be injected into your services. If a service definition were available to change, you would set the autowiring_types parameter to specify a default implementation of dependency. But usualy entity manager services are defined by DoctrineBundle and you can not configure it directly. (As I know, Doctrine configuration doesn't provide options to set up that.)

So, the easiest way is to manually specify the entity manager: just pass a entity manager service ID (doctrine.orm.XXX_entity_manager) to constructor arguments of your services.

services:       
    app.security.user_login_form_authenticator:
        class: AppBundle\Security\UserLoginFormAuthenticator
        arguments: [ '@doctrine.orm.XXX_entity_manager' ]

    app.security.admin_login_form_authenticator:
        class: AppBundle\Security\AdminLoginFormAuthenticator
        arguments: [ '@doctrine.orm.YYY_entity_manager' ] 

Obviously, if services have other dependendecies, you also need to specify them.

Timurib
  • 2,735
  • 16
  • 29