如何在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,
))
答案 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