I work with a Page entity (to manage a list a page...)
I have a entity Field Type :
$builder
->add('parent', 'entity', array(
'class' => 'EliophotBackBundle:Page',
'query_builder' => function(EntityRepository $er) {
return $er->createQueryBuilder('p')
->join('p.translations', 'pt')
->where('p.id = pt.translatable')
->andWhere('pt.locale = :lang')
->setParameter('lang', 'fr')
;
},
'label' => 'Page parente ?',
'multiple' => false,
'required' => false,
'empty_value' => 'Choisissez une page parente',
'empty_data' => null,
));
and I have a __toString method in my Page entity to display the page name into the select field :
public function __toString()
{
return (string) $this->getName();
}
So in my twig template I have a select field that displays the list of the page like this :
<select>
<option value="1">page 1</option>
<option value="2">page 2</option>
<option value="3">page 3</option>
...
</select>
But when I submit the form, I only get the value of the select choiced, "page 1" for example.
But I want to stored the id present in the value in my database, not the string... So how can I get the value of the select in my controller ?
I try this but it only return the name of the page selected :
$myForm->get('parent')->getData(); //dump = 'page 1' for example
Aucun commentaire:
Enregistrer un commentaire