I want to make dropdownlist from single record, I have two table like this:
Column prodi_pilihan_1_id and prodi_pilihan_2_id referenced from prodi_penerima table.
I want make dropdown for column prodi_pilihan_1_id and prodi_pilihan_2_id but the option text is from prodi_penerima that is nama_prodi_penerima so the dropdown be like this:
<select>
<option value= '2'> BBB </option>
<option value= '4'> DDD </option>
</select>
So suggest from How to make dropdown in Yii2 from one record, I created controller like this:
$model4 = Pendaftar::find()
->select(['pro1.id_prodi_penerima as id_prodi_pilihan_1','pro1.nama_prodi_penerima as prodi_pilihan_1','pro2.id_prodi_penerima as id_prodi_pilihan_2','pro2.nama_prodi_penerima as prodi_pilihan_2'])
->from('pendaftar')
->leftJoin('prodi_penerima as pro1', 'pro1.id_prodi_penerima=pendaftar.prodi_pilihan_1')
->leftJoin('prodi_penerima as pro2', 'pro2.id_prodi_penerima=pendaftar.prodi_pilihan_2')
->andWhere(['=','id_user_pendaftar',$id])
->asArray()
->One();
$rows=\yii\helpers\ArrayHelper::map(array_filter([$model4['prodi_pilihan_1'],$model4['prodi_pilihan_2']]),function($item){
return $item;
},function($item){
return $item;
});
//return $this->render('lulus_ujian', ['rows' => $rows]);
return $this->renderAjax('lulus_ujian', [
'model' => $this->findModel($id),
'rows' => $rows,
]);
I render that into the view and then into the form, the form is like this:
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'status_lulus_tes_pendaftar')->dropDownList([ 'yes' => 'Yes', 'no' => 'No', ], ['prompt' => '']) ?>
<?= $form->field($model, 'prodi_lulus')->dropDownList($rows, ['prompt' => '']) ?>
<?= $form->field($model, 'ket_lulus_ujian')->textarea(['rows' => '6']) ?>
<div class="form-group">
<?= Html::submitButton('Save', ['class' => 'btn btn-danger']) ?>
</div>
<?php ActiveForm::end(); ?>
The dropdown is working, but the value and the option is having the same value:
<select>
<option value= 'BBB'> BBB </option>
<option value= 'DDD'> DDD </option>
</select>
I want save the model where the option value is id_prodi_penerima.
What I must do so the option value is 2 and 4 like this:
<select>
<option value= '2'> BBB </option>
<option value= '4'> DDD </option>
</select>

print_r($model4), what does it show, and the question you are referring to previously it was for one row, do you still want to draw the menu the same way , means you want to show all the columns in the dropdown, for a single row, and use the option value as another column rather than keeping the same columns for the options value and text.Array ( [id_prodi_pilihan_1] => 2 [prodi_pilihan_1] => BBB [id_prodi_pilihan_2] => 4 [prodi_pilihan_2] => DDD )