I have researched a lot in this topic, but was not able to find a perfect solution.
So i have a dropdown list which when i’m updating a record doesn’t show the previously selected value.It simply shows the prompt value,I want it to show the previously selected one.
Please help me with this .
This is my _form.php
<?= $form->field($model, 'deptloc')->dropDownList(
ArrayHelper::map(\app\models\Location::find()->all(), 'id', 'locname'),
['prompt' => 'Select Location'],
['options' => [ $_GET['id'] => ['Selected'=>'selected']]]
)
?>
<?= $form->field($model, 'deptid')->widget(DepDrop::classname(), [
'pluginOptions'=>[
'depends'=>['emp-deptloc'],
'placeholder'=>'Select...',
'url'=>Url::to(['/connect/locs'])
]
]);
?>
And this is my actionUpdate:
public function actionUpdate($id)
{
$model = $this->findModel($id);
//print_r($model);die;
if ($model->load(Yii::$app->request->post())) {
$model->empeducation=implode(',',$model->empeducation);
$filename = $model->file;
$model->file=UploadedFile::getInstance($model,'empresume');
// if( ($model->file)== "")
// {
// $model->save(false);
// return $this->redirect(['index', 'id' => $model->empid]);
// }
$model->file->saveAs('uploads/'.$filename.rand(1,1000).'_'.$model->file);
$model->empresume=rand(1,1000).'_'.$model->file;
$model->save(false);
return $this->redirect(['index', 'id' => $model->empid]);
}
return $this->render('update', [
'model' => $model,
]);
}
I want to put it for both of my dropdown (depdrop as well). How can i achieve this?