搜索角色FOSu

时间:2015-03-26 22:54:00

标签: symfony fosuserbundle

我想用(roles = ROLE CHAUFFEUR)收集我的所有用户,但我无法找到方法 得到所有“司机”

class VehiculeForm extends AbstractType {

    public function buildForm(FormBuilderInterface $builder, array $options) {
        $builder
                ->add('mat_vehicule')
                ->add('dateMiseCirculation')
                ->add('marquevehicule')
                ->add('marquevehicule', 'entity', array(
                    'class' => 'KiboTaxiUserBundle:UserKibo',
                    'property' => 'username',
                    'label' => 'Choisir:',
                    'query_builder' => function(UserKiboRepository $er) {
                        return $er->createQueryBuilder('u')
                                ->where('u.roles  = a:1:{i:0;s:14:"ROLE_CHAUFFEUR";}  ');
                    },
                ))
                ->add('submit', 'submit');
    }

    public function getName() {
        return 'Vehicule';
    }

}

1 个答案:

答案 0 :(得分:1)

您必须像LIKE一样查询您的角色:

$queryBuilder
->where("u.roles LIKE :role")
->setParameter("role", "%".$role."%");