Symfony 2.6:如何获取用于登录的当前提供商


Symfony 2.6 : How to get the current provider used to log in?

我在SF2.6项目中遇到了一个问题。我有两种类型的用户(客户、员工),所以我使用的是多实体提供商

providers:
    chain_provider:
        chain:
            providers: [employee, client]
    employee:
        entity: { class: SpeedDev'MyprojectsBundle'Entity'Employee, property: emailEmp }
    client:
        entity: { class: SpeedDev'MyprojectsBundle'Entity'Client, property: contactemailClient }

我可以作为客户或员工登录到我的应用程序,SF会在正确的表中检查凭据。

我的问题是,我需要检索员工或客户sf之间的哪个实体用作提供者,这样我就知道在$this->getUser()->getIdEmp()或$this->getUser(()->getIdClient()之间要使用哪个实体的函数

提前感谢

您只需检查您的$this->getUser()是否为instanceof您想要的实体:

if ($this->getUser() instanceof SpeedDev'MyprojectsBundle'Entity'Employee) {
    // this is employee
}