doctrine2 - ZF2 - set selected value on Select Element -


i've problem dropdown list zend framework 2 & doctrine. put "selected" attribute on dropdown list options pass selected

my code :

controller :

public function editaction() {     // error message during addaction     $this->layout()->setvariable("messageerror", $this->flashmessenger()->geterrormessages());      $auth = $this->getauthservice();     if ($auth->hasidentity()){         $builder = new annotationbuilder();         // 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 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 typeplan list (<select>)         $typesplan = $this->getentitymanager()->getrepository("admin\entity\typeplan")->getarrayofall();         $form->get('typeid')->setvalueoptions($typesplan);         $form->get('typeid')->setvalue("{$plan->gettypeid()->getid()}");         // options 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()) {             [...]              } } 

with

$localites = $this->getentitymanager()->getrepository("admin\entity\localite")->getarrayofall();     $form->get('localiteid')->setvalueoptions($localites); 

i populate dropdown correctly,

$form->get('localiteid')->setvalue("{$plan->getlocaliteid()->getid()}"); 

just set "selected" on option defined :

$plan->getlocaliteid()->getid() 

so why options selected in dropdown ?!

information : it's same typeid no statut

personally don't know if getarrayofall() such function exists, assume correctly passing array form,

i think should doing set value.

 $form->get('localiteid')->setvalue($plan->getlocaliteid()->getid()); 

but since populating drop down guess approach not work best drop down. need

   $form->get('localiteid')->setattributes(array('value'=>$plan->getlocaliteid()->getid(),'selected'=>true)); 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -