How can I access two entity managers in the security user provider class in Symfony2?
Purpose: The app needs to access to two databases. One is for loading the security user and another is to create an entry of the user.
Current situation: only the entity manager is used. I am injecting another entity manager. However, the default entity manager that is configured in the "providers" of security.yml is used. When I uncomment this then default_manager is used. In any case, only one entity manager is used.
Security.yml:
providers:
main:
entity:
class: Entity\sm\UserPro
property: apiKey
manager_name: userpro_manager
Security user provider:
class UserProviderMP implements AuthenticationProviderInterface{
public function __construct(
UserProviderInterface $userProvider,
EntityManagerFactory $entityManagerFactory)`
I am using entitymanagerfactory
to get access to another entity manager:
$this->entityManagerFactory->getentityManager();
How can I access a different entity manager other than the entity manager configured in security.yml?
Actually, there is no issue in my code. There is a wrapper class that always returns the same entity manager instead of the entity manager that the code is asking for while running my tests. I have disabled this wrapper class and it works perfectly fine.
Thanks!!!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.