Symfony:带有查询生成器where子句的FormBuilder EntityType

时间:2018-09-27 10:40:14

标签: symfony doctrine-orm query-builder formbuilder symfony-3.4

Symfony 3.4

我正尝试在下拉列表中加载用户引用的客户端列表。

每个用户都可以在下拉列表中选择已引用的客户端,而不是整个客户端列表。

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

表格

$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']
            ])
[...]

如何构建带有仅填充这些数据的下拉菜单<select>的表单?

1 个答案:

答案 0 :(得分:1)

替换

-> where('u.referer',':uid')<------此处错误

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