如何将自定义字段添加到 Symfony2 FOSUserBundle 中的某些用户角色?

How to add custom fields to some user roles in the Symfony2 FOSUserBundle?

我的网络应用程序 "users" 有 3 个角色 - MentorMentee主管。我已经了解如何使用 FOSUserBundle 来管理用户并使用 ROLE_ 前缀分配角色。但是我想存储一些特定于特定角色的额外信息,比如导师有 joindatesessionscompleted,主管有 salary。我可以为每个角色创建 3 个单独的实体,并在必要时添加额外的字段。然而,当在我的项目的 config.yml 文件中设置 FOSUserBundle 时,它​​只有指定一个实体的空间:

app/config/config.yml
fos_user:
db_driver: orm # other valid values are 'mongodb' and 'couchdb'
firewall_name: main
user_class: AppBundle\Entity\Mentor **# how do I specify the other 2 entities here?**
from_email:
    address: "%mailer_user%"
    sender_name: "%mailer_user%"

不幸的是,FosUserBundle 没有证明弹性。而不是这个 ypo 可以使用

PUGXMultiUserBundle

或者简单地为具有可选字段的用户创建一个 class,如果不属于给定角色,则该字段将为空。