Symfony将Doctrine Entity Manager注入一个类

时间:2014-04-01 19:02:14

标签: php symfony doctrine-orm

所以我添加了实体管理器作为参数:

$container->setDefinition('ldap.security.authentication.provider',
    new Definition('Client\IntranetBundle\LDAP\LDAPAuthenticationProvider', array(
        new Reference("ldap_user_provider"),
        new Reference("ldap_manager")
    )))
    ->addArgument("ldap.security.authentication.provider")
    ->addArgument("doctrine.orm.entity_manager");

但是在我的课堂上,如果我回应这个论点,我得到的就是这个字符串:secured_area

如何获得实际的实体经理?

这是构造方法:

public function __construct(LDAPUserProvider $userProvider, LDAPManagerInterface $ldapManager, $entityManager, $providerKey) {
    //var_dump($userProvider);
    //var_dump($ldapManager);
    //var_dump($entityManager);
    //var_dump($providerKey);
    $this->userProvider = $userProvider;
    $this->ldapManager = $ldapManager;
    $this->entityManager = $entityManager;
    $this->providerKey = $providerKey;
}

$ entityManager的var_dump是字符串(12)“secured_area”

$ providerKey的var_dump是string(37)“ldap.security.authentication.provider”

1 个答案:

答案 0 :(得分:0)

$container->setDefinition('ldap.security.authentication.provider',
new Definition('Client\IntranetBundle\LDAP\LDAPAuthenticationProvider', array(
    new Reference("ldap_user_provider"),
    new Reference("ldap_manager"),
    new Reference("doctrine.orm.entity_manager"),
    /* Here you should pass providerKey */
)))

这是如何定义服务的,但我建议您在创建自定义身份验证提供程序之前阅读http://symfony.com/doc/current/cookbook/security/custom_authentication_provider.html

相关问题