-1

I want to collect all my users with (roles=ROLE_CHAUFFEUR) but i can't fin a way to get all 'chauffeurs'

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';
    }

}
Companjo
  • 1,789
  • 18
  • 24
Ghassen Khelif
  • 151
  • 2
  • 9
  • 1
    Here is the same problem I supose http://stackoverflow.com/questions/9016914/symfony-2-fos-bundle-how-to-select-users-with-a-specific-role – Greg Mar 28 '15 at 10:35

1 Answers1

1

You have to query for your roles with LIKE like this:

$queryBuilder
->where("u.roles LIKE :role")
->setParameter("role", "%".$role."%");
Benjamin Paap
  • 2,744
  • 2
  • 21
  • 33