问题
I set symfony choiceType value from inside the controller by using this:
$editForm->get('userJobTitle')->setData($job->getJobTitle()->getId());
How to do it for multiple choiceType? the following method isn't working
$editForm->get('userskills')->setData($job->getSkills());
where getSkills
function return Doctrine collection.
回答1:
setData()
method requires array of strings which contain the values of selected options so i do:
$usSkills = $job->getSkills()->getValues();
$vals = array();
foreach ($usSkills as $us){
$vals[] = (string)$us->getId();
}
$editForm->get('userskills')->setData($vals);
and that solved the problem
来源:https://stackoverflow.com/questions/45376155/symfony-set-data-to-multiple-choicetype