Answer the question
In order to leave comments, you need to log in
How to get value of selected array element in select in yii2?
Good afternoon! I don’t understand something, please tell me, I send a field with the selected select in the form:
<?php $items = [
'0' => 'Проект1',
'1' => 'Проект2',
'2' => 'Проект3',
];
?>
<?= $form->field($model, 'service')->dropDownList($items) ?>
Answer the question
In order to leave comments, you need to log in
And why do you put 0 , 1 and 2 in the values if you want to get Project1, Project2 and Project3? Put what you need in there.
<?php
$items = [
'Проект1' => 'Проект1',
'Проект2' => 'Проект2',
'Проект3' => 'Проект3',
];
Yes, at least make the model a static method
static function getServiceList()
{
return [ 'Проект1', 'Проект2', 'Проект3'];
}
Model::getServiceList()[$id]
get a name
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question