Last active
December 15, 2015 23:59
-
-
Save docteurklein/5344071 to your computer and use it in GitHub Desktop.
Form ChoiceType: entityChoiceList vs ObjectChoiceList
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//$this->getUser()->getCandidates() returns an array of EUser entities | |
$entityChoiceListForm = $this->createForm('choice', null, array( | |
'choice_list' => new EntityChoiceList( | |
$this->get('doctrine')->getManager(), | |
'SSCoreBundle:EUser', | |
'name', | |
null, | |
$this->getUser()->getCandidates() | |
), | |
)); | |
$objectChoiceListForm = $this->createForm('choice', null, array( | |
'choice_list' => new ObjectChoiceList($this->getUser()->getCandidates(), 'name'), | |
)); | |
$objectChoiceListForm->bind(array('choice' => 0)); // select the first item of the list | |
$entityChoiceListForm->bind(array('choice' => 0)); // select the first item of the list | |
assertEquals($entityChoiceListForm->getData(), $objectChoiceListForm->getData(), 'form data should be the same'); // failure | |
// The `ObjectChoiceList` fails to retrieve the element of index: 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@bschussek any idea why this behavior, or if I do something wrong ?