for my drop-down list I am using this code.
<?= $form->field($medicinerequest, '[' . $id . ']' . 'medicine_name')
->DropDownList(ArrayHelper::map(\app\models\Medicine::find()
->asArray()->all(), 'id', 'medicine_name','medicine_id' ),
[ 'prompt' => 'Please Select' ])?>
I am getting the drop-down list as in the picture. But I want it to be concatenated by hyphen(-) in one line. How can I do this?
You can set
$var
in kartik Depdrop widget, as the same scenario in the Dropdown widget here We use kartik depdrop widgetOk I found the solution. I will welcome if there is a better solution.
I have created a function in the model Medicine.php
and then in the arrayhelper replaced medicine_name with medicineName and Now I am getting what I was looking for.
The anonymous function could be
You can check here!
ArrayHelper::map($array, $from, $to, $group)
usesArrayHelper::getValue()
to obtain the values of$from
,$to
and$group
.ArrayHelper::getValue()
allows you to pass closures.As such you can set
$to
as