[英]Symfony2 with FOSUserBundle - how to add roles without hierarchy to my application
I am creating a web application where I need 2 roles. 我正在创建一个Web应用程序,我需要2个角色。 Medic and Patient.
医生和病人。 They are connected through a many-to many relation (patients can have several medics and vice versa), and the medic is supposed to be able to see its patient's data, but not edit it.
它们通过多对多关系连接(患者可以有几个医生,反之亦然),医生应该能够看到患者的数据,但不能编辑它。
I am using FOSUserBundle and have followed the documentation on using roles. 我正在使用FOSUserBundle并遵循使用角色的文档。 However, the documentation as I see it does not help me in creating these roles.
但是,我看到的文档对创建这些角色没有帮助。 I tried the security part of symfony2 documentation, but it shows how to create a role hierarchy - not helping in my case.
我尝试了symfony2文档的安全性部分,但它显示了如何创建角色层次结构 - 在我的情况下没有帮助。
How do I proceed in solving this issue? 我该如何解决这个问题?
EDIT: To be more precise: The real question is how to add the two roles. 编辑:更确切地说:真正的问题是如何添加这两个角色。 Maybe I don't need the groups...
也许我不需要这些团体......
I think I solved it: 我想我解决了它:
http://symfony.com/doc/current/book/security.html#roles http://symfony.com/doc/current/book/security.html#roles
This role doesn't need to be defined anywhere - you can just start using it.
此角色不需要在任何地方定义 - 您可以开始使用它。
EDIT: simply do $user->addRole("ROLE_MEDIC"); 编辑:只需执行$ user-> addRole(“ROLE_MEDIC”);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.