drop down menu - Dropdownlist selected value not showing while updating the form -
here explain problem
i have dropdownlist called companytype, contains value 1+1, 1+2, 1+3, 1+4, 1+5, 1+6, 1+7
while creating form have select value eg:1+4 , store, same while updating value getting change select companytype [prompt]
<?= $form->field($model, 'companytype')->dropdownlist([ '1' => '1+1', '2' => '1+2', '3' => '1+3', '4' => '1+4', '5' => '1+5', '6' => '1+6', '7' => '1+7', ], ['prompt' => 'select company type', ]) ?>
here have added 2 images can understand question
gridview of created form
updating same form
updated:
mycontroller code:
public function actioncreate() { if(yii::$app->user->can( 'create-company' ) ) { $model = new company(); if ($model->load(yii::$app->request->post()) ) { $model->createdat = date('y-m-d'); $ro = $model->relationoption; if($ro == 'fixed') { $commalist = implode(', ', $model->relation); $model->relation = $commalist; } $model->save(); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', [ 'model' => $model, ]); } } else { throw new forbiddenhttpexception; } }
controller code update
public function actionupdate($id) { if(yii::$app->user->can('update-company')) { $model = $this->findmodel($id); if ($model->load(yii::$app->request->post()) ) { $model->updatedat = date('y-m-d h:m:s'); $ro = $model->relationoption; if($ro == 'fixed') { $commalist = implode(', ', $model->relation); $model->relation = $commalist; } $model->save(); return $this->redirect(['view', 'id' => $model->id]); } return $this->render('update', [ 'model' => $model, ]); } else { throw new forbiddenhttpexception; } }
is there answer, pls answer me
i dont see $model->companytype = 4 in update action. can add update action , check. update action should like:
public function actionupdate($id) { if(yii::$app->user->can('update-company')) { $model = $this->findmodel($id); $model->companytype = 4; if ($model->load(yii::$app->request->post()) ) { $model->updatedat = date('y-m-d h:m:s'); $ro = $model->relationoption; if($ro == 'fixed') { $commalist = implode(', ', $model->relation); $model->relation = $commalist; } $model->save(); return $this->redirect(['view', 'id' => $model->id]); } return $this->render('update', [ 'model' => $model, ]); } else { throw new forbiddenhttpexception; } }
Comments
Post a Comment