I have a form that has location field. Creating a ChoiceType class with dropdown and for options I have defined all the locations in config.yml as parameters.
config.yml:
parameters:
locations:[location1, location2, location3]
Controller Form Field:
$form = $this->createFormBuilder($abc)
->add('location', ChoiceType::class, array(
'label' => 'Select Location',
'choices'=> $this->getParameter('locations'),
))
->getForm();
This is displaying array location i.e. 0 for location1, 1 for location2 etc, But I want to display array values.
Other things I tried, placing this parameters in a array and then trying array_value options. I got to display location by:
$arrayincontroller=$this->getParameter('locations')
and in form:
->add('location', ChoiceType:class, array('label' => 'Select Location', 'choices'=> array($arrayincontroller[0] => $arrayincontroller[0])
but don't want to write each and every location like this. Is there any better method to pass values to form. Tried to include foreach but guess I can't do that.