Answer the question
In order to leave comments, you need to log in
How to specify in the option value attribute the value of the option itself for the entity field in a form in Symfony 2?
Welcome all. Need a hint how to solve the following misunderstanding:
1. There is a form class ( this form is embedded into another form ), in which there is only one field of the entity type:
...
$builder->add( 'olcode', 'entity', array( 'label' => 'Код: ',
'class' => 'Acme\AppBundle\Entity\Show\Oldemand',
'query_builder' => function ( EntityRepository $er ) {
return $er->createQueryBuilder( 'u' )
->groupBy( 'u.olcode' )
->orderBy( 'u.olcode', 'ASC' );
},
'property' => 'olcode',
'required' => false,
)
);
...
...
<option value="2137864">Silver</option>
...
...
<option value="Silver">Silver</option>
...
Answer the question
In order to leave comments, you need to log in
"Under the hood" is the following (very simplified):
$choiseList = [];
foreach ($entities as $entity) {
$choiseList[$entity->getId()] = (string) $entity;
}
// $choiseList = [
// 5 => 'A',
// 6 => 'B',
// 81 => 'F',
// // ...
// ];
//
// <option value="5">A</option>
// <option value="6">B</option>
// <option value="81">F</option>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question