Symfony / Formbuilder。在querybuilder上选择特定字段

时间:2017-08-29 08:14:50

标签: symfony formbuilder

如何在symfony上的表单中选择查询构建器上的特定字段?

我正在试图这样做:

        ->add('tienda', EntityType::class, array(
            'class' => 'AdminBundle:MyTable',
            'query_builder' => function (EntityRepository $er) {
                return $er->createQueryBuilder('select tienda')
                    ->distinct()
                    ->orderBy('u.tienda', 'ASC');
            },
            'required' => false,
        ))

1 个答案:

答案 0 :(得分:0)

使用choice_label选项

    ->add('tienda', EntityType::class, array(
        'class' => 'AdminBundle:MyTable',
        'choice_label' => 'xxx',
        'query_builder' => function (EntityRepository $er) {
            return $er->createQueryBuilder('u')
                ->distinct()
                ->orderBy('u.tienda', 'ASC');
        },
        'required' => false,
    ))

http://symfony.com/doc/current/reference/forms/types/entity.html#choice-label