Ich habe ein Formular, das Standort-Feld hat. Erstellen einer ChoiceType
Klasse mit Dropdown und für Optionen habe ich alle Orte in config.yml als Parameter definiert.Wie bekomme ich Config Array-Parameter im Controller, um es an einen Zweig zu senden, um es im Formular anzuzeigen
config.yml:
parameters:
locations:[location1, location2, location3]
Controller-Formularfeld:
$form = $this->createFormBuilder($abc)
->add('location', ChoiceType::class, array(
'label' => 'Select Location',
'choices'=> $this->getParameter('locations'),
))
->getForm();
Dies ist die Anzeige Matrixlokation heißt 0
für location1, 1
für location2 etc, aber ich will Array-Werte angezeigt werden soll.
Andere Dinge, die ich versuchte, diese Parameter in ein Array platzieren und dann array_value
Optionen versuchen. Ich habe Standort angezeigt werden durch:
$arrayincontroller=$this->getParameter('locations')
und in Form:
->add('location', ChoiceType:class, array('label' => 'Select Location', 'choices'=> array($arrayincontroller[0] => $arrayincontroller[0])
wollen aber nicht jede einzelne Lage, so schreiben. Gibt es eine bessere Methode, um Werte an Formulare zu übergeben? Versucht, foreach einzuschließen, aber rate ich kann das nicht tun.
Vielen Dank, es hat funktioniert –
Besteht ein Nachteil darin, -> add ('location', ChoiceType: class, array ('label' => 'Standort auswählen', 'Auswahlmöglichkeiten' => $ this-> getParameter ('locations'); –
Hallo @HarshulR ja kein Problem zu tun haben Sie direkt – Matteo