Symfony2 FOSUserBundle角色实体 [英] Symfony2 FOSUserBundle Role entities

查看:149
本文介绍了Symfony2 FOSUserBundle角色实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在试图找出实现原则的最佳方式,将角色实体作为与FOSUserBundle兼容的M2M关系。以前,我只是使用默认实现的字符串,并且坚持使用一个doctrine数组映射。

I'm currently trying to figure out the best way to implement doctrine persisted Role entities as a M2M relationship compatible with FOSUserBundle. Previously I was using just strings with the default implementation and was persisting it with a doctrine array mapping.

现在我需要作为独立的角色,因为我们想要构建一个管理员后台,其他人可以授予用户角色。

Now I need to have roles as seperate entites as we want to build an admin backend where others can grant users roles.

基本上,这是一个痛苦的屁股。 FOS接口是为字符串表示而不是角色实体构建的。改变实现,你打破了很多东西,即FOS命令来宣传用户。而且很难弄清楚哪些接口需要允许symfony2安全系统继续正常工作。

Basically, it's a pain in the ass. The FOS interfaces are built for string representations, not Role entities. Change the implementation, you break a lot of stuff i.e. FOS commands to promote users. And it's hard to figure out exactly which pieces of the interfaces are needed to allow the symfony2 security system to continue working correctly.

我可以重写角色管理代码并使用角色实体尽可能多,例如:

I could rewrite the role management code and use Role entities as much as possible, e.g.:

$user->addRole(new Role('ROLE_FOO'));

但是这会破坏命令和可能存在的代码?

But that breaks commands and possibly existing code?

或继续使用:

$user->addRole('ROLE_FOO');

并且在中配置角色/实体管理器代码addRole()(坏的设计)。

我注意到这是一个灰色区域(FOS的角色实体),并在symfony2板上提及,但没有体面的解决方案。

I've noticed this is a grey area (Role entities with FOS) and has been mentioned on the symfony2 boards and round here, but no decent solutions.

任何人都有任何经验或想到一个体面的解决方案?

Anyone had any experience or can think of a decent solution?

推荐答案

我决定使用数组/ ArrayCollection实现的混合。我试图尽可能地遵循现有的接口,以免破坏安全系统。我已经将我的解决方案记录在 http://blog.jmoz.co.uk/symfony2-fosuserbundle-role-实体

I decided to go with a mix of an array/ArrayCollection implementation. I tried to follow the existing interfaces as much as possible so as not to break the security system. I have documented my solution at http://blog.jmoz.co.uk/symfony2-fosuserbundle-role-entities

这篇关于Symfony2 FOSUserBundle角色实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆