以奏鸣曲管理员的编辑形式为用户设置角色 [英] set role for users in edit form of sonata admin

查看:120
本文介绍了以奏鸣曲管理员的编辑形式为用户设置角色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Symfony 2.1进行项目.我使用FOSUserBundle来管理用户& SonataAdminBundle用于管理用途.

I'm using Symfony 2.1 for a project. I use the FOSUserBundle for managing users & SonataAdminBundle for administration usage.

对此我有一些疑问:

  1. 作为管理员,我想在用户编辑表单中设置用户的角色.如何访问role_hierarchy中的角色?以及如何使用它们作为选择字段,以便管理员可以为用户设置角色?

  1. As an admin, I want to set roles from users in users edit form. How can I have access to roles in role_hierarchy? And how can I use them as choice fields so the admin can set roles to users?

当我在列表中显示角色时,它显示为这样的字符串:

When I show roles in a list, it is shown as string like this:

[0 => ROLE_SUPER_ADMIN] [1 => ROLE_USER] 

如何将其更改为此?

ROLE_SUPER_ADMIN, ROLE_USER 

我的意思是,仅具有数组的值.

I mean, having just the value of the array.

推荐答案

我找到了我的第一个问题的答案! 我在configureFormFields函数中添加如下角色:

i found an answer for my first question!(but the second one in not answered yet..) i add the roles like below in configureFormFields function :

  protected function configureFormFields(FormMapper $formMapper) {
  //..
 $formMapper
 ->add('roles','choice',array('choices'=>$this->getConfigurationPool()->getContainer()->getParameter('security.role_hierarchy.roles'),'multiple'=>true ));
}

如果有人回答第二个问题,我会很高兴的:)

I would be very happy if anyone answers the second question :)

这篇关于以奏鸣曲管理员的编辑形式为用户设置角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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