我在symfony 3.4.24的同一页面上有两个表单一
他们两个都有相同的领域。但是在第一种情况下,选择值是id,在第二种情况下,选择值是代码:
// first form
$builder->add('store', EntityType::class, array(
'class' => Store::class,
'query_builder' => function (StoreRepository $repository) {
return $repository->createQueryBuilder('s');
},
'choice_value' => 'id', // <= Here is the difference
))
// second form
$builder->add('store', EntityType::class, array(
'class' => Store::class,
'query_builder' => function (StoreRepository $repository) {
return $repository->createQueryBuilder('s');
},
'choice_value' => 'code', // <= Here is the difference
))
我的html的值是两种形式的代码!
<!-- First form -->
<option value="AMI">AMI</option>
<!-- second form -->
<option value="AMI">AMI</option>
应该是:
<!-- First form -->
<option value="24">AMI</option>
<!-- second form -->
<option value="AMI">AMI</option>
注意:没有'query_builder'参数,它可以工作