andreaem
andreaem

Reputation: 1655

Symfony: FormBuilder EntityType with Query Builder where clause

Symfony 3.4

I'm trying to load in a dropdown a list of clients refered by the users.

Each user can select in the dropdown the clients that has refered and not the whole clients list.

ERROR : [Syntax Error] line 0, col 58: Error: Expected =, <, <=, <>, >, >=, !=, got 'AND'

FORM:

$form = $this->createFormBuilder($expertations)
            ->add('client', EntityType::class, [
                'class' => 'AppBundle:Clients',
                'placeholder' => '-- Seleziona --',
                'query_builder' => function (EntityRepository $er) {
                    return $er->createQueryBuilder('u')
                        ->where('u.referer', ':uid')   <------ ERROR HERE
                        ->setParameter('uid', $this->getUser()->getId())
                        ->orderBy('u.name', 'ASC');
                },
                'choice_label' => 'name',
                'choice_value' => 'id',
                'label' => 'Cliente',
                'attr' => ['class' => 'form-control']
            ])
[...]

How can be built a form with a dropdown <select> filling only these data?

Upvotes: 1

Views: 4188

Answers (1)

AythaNzt
AythaNzt

Reputation: 1057

Replace

->where('u.referer', ':uid') <------ ERROR HERE

for

->where('u.referer = :uid')

Upvotes: 2

Related Questions