ZF2 - set gewählte Wert am Select-Element

Ich habe ein problem mit dropdown-Liste mit Zend Framework 2 & Lehre.
Ich würde die "selected" - Attribut auf mein dropdown-Liste, aber alle Optionen pass auf ausgewählte

Mein code :

Controller :

public function editAction()
{
    //get error message during addAction
    $this->layout()->setVariable("messageError", $this->flashMessenger()->getErrorMessages());

    $auth = $this->getAuthService();
    if ($auth->hasIdentity()){
        $builder = new AnnotationBuilder();
        //Get id of StaticContent
        $id = (int)$this->getEvent()->getRouteMatch()->getParam('id');
        if (!$id) {
            $this->flashMessenger()->addErrorMessage("Aucun plan choisi !");
             return $this->redirect()->toRoute('admin/plans');
        }
        $plan = $this->getEntityManager()->getRepository("Admin\Entity\Plan")->find((int)$id);
        $form = $builder->createForm($plan);
        //Find options for Localite list (<select>)
        $localites = $this->getEntityManager()->getRepository("Admin\Entity\Localite")->getArrayOfAll();
        $form->get('localiteid')->setValueOptions($localites);
        $form->get('localiteid')->setValue("{$plan->getLocaliteid()->getId()}");

        //Find options for TypePlan list (<select>)
        $typesPlan = $this->getEntityManager()->getRepository("Admin\Entity\TypePlan")->getArrayOfAll();
        $form->get('typeid')->setValueOptions($typesPlan);
        $form->get('typeid')->setValue("{$plan->getTypeid()->getId()}");
        //Options for Statut list (<select>)
        $form->get('statut')->setValueOptions(array('projet'=>'Projet', 'valide'=>'Validé'));
        $form->get('statut')->setValue($plan->getStatut());
        $form->setBindOnValidate(false);
        $form->bind($plan);
        $form->add(array(
            'name' => 'submit',
            'attributes' => array(
                'type'  => 'submit',
                'value' => 'Modifier',
                'id' => 'submitbutton',
                'class' => "btn btn-primary"
            ),  
        ));
        $request = $this->getRequest();
        if ($request->isPost()) {
            [...]

            }
}

Mit

$localites = $this->getEntityManager()->getRepository("Admin\Entity\Localite")->getArrayOfAll();
    $form->get('localiteid')->setValueOptions($localites);

ich füllen mein dropdown-richtig, in der Regel mit

$form->get('localiteid')->setValue("{$plan->getLocaliteid()->getId()}");

nur einstellen "aktiviert" - option definiert durch :

$plan->getLocaliteid()->getId()

Also warum sind alle Optionen markiert, die in meinem dropdown ?!

Informationen : Es ist das gleiche für den typeId-aber kein Statut

InformationsquelleAutor RudySkate | 2013-08-07

Schreibe einen Kommentar