繁体   English   中英

如何在Symfony2 FOSUserBundle中向某些用户角色添加自定义字段?

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

我遇到的情况是,我的Web应用程序的“用户”有3个角色-MentorMenteeSupervisor 我已经了解了如何使用FOSUserBundle来管理用户并使用ROLE_前缀分配角色。 但是,我还想存储一些特定于特定角色的额外信息,例如,Mentors joindate sessionscompleted并且完成了sessionscompleted ,而Supervisor joindate有了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

或为用户创建一个带有可选字段的类,如果不属于给定角色,则该字段为null。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM