Answer the question
In order to leave comments, you need to log in
How to display the name of the field corresponding to this id in the form instead of the number (id)?
Hello everybody! Please tell me, when switching to the view by one of the values, I pass the identifier of the parent element. After switching to the view, the identifier of the parent element (parent_id) is set in the corresponding field, but since it is not very convenient to display the identifier, I would like to see instead of id - the name of the field (name) corresponding to the given id. In this case, I have id = 1, and the field name = User's workplace. Tell me how to display its name instead of an identifier?
At the moment, I have written such a structure,
$parent = Type::find()->where(['parent_id' => 0])->all();
$items = ArrayHelper::map($parent, 'id', 'name');
Array
(
[1] => Рабочее место пользователя
[5] => Периферийные устройства
[11] => СПД/ЛВС
[28] => Билетно-кассовое оборудование
)
Answer the question
In order to leave comments, you need to log in
$form->field($model, "field")->dropDownList($items, ['prompt' => 'Выберите'])
$items = Type::find()->select(['name'])->where(['parent_id' => 0])->indexBy('id')->column();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question