Answer the question
In order to leave comments, you need to log in
How to display database values (dropdowlist) in text format on the website page?
The page site should display text values and not the values from the database
For example , the site should display the value Lieutenant instead of '1'
<?php
$items = [
'Rank' => [
'0' => 'Jr. Lieutenant',
'1' => 'Lieutenant',
'2' => 'Senior Lieutenant',
'3' => 'Captain',
'4' => 'Major',
'5' => 'Polkovnik',
'6' = > 'Colonel',
],
];
$params = [
'prompt' => 'Select a status...',
];
echo $form->field($model, 'hit')->dropDownList($items,$params);
?>
Answer the question
In order to leave comments, you need to log in
Good afternoon.
It looks like it should be like this:
If you get only an integer from the base and want to match it with text, then create a public static method in the model that will return an array. Pretty much the same as you did.
// В моделе
public static function getItems()
{
return [
'0' => 'мл.Лейтенант',
'1' => 'Лейтенант',
'2' => 'ст.Лейтенант',
'3' => 'Капитан',
'4' => 'Майор',
'5' => 'п.Полковник',
'6' => 'Полковник',
];
// В представлении
$form->field($model, 'hit')->dropDownList(ModelName::getItems(), ['prompt' => 'Select'])
slo_nik :
<?php
$items = [
'Звание' => [
'0' => 'мл.Лейтенант',
'1' => 'Лейтенант',
'2' => 'ст.Лейтенант',
'3' => 'Капитан',
'4' => 'Майор',
'5' => 'п.Полковник',
'6' => 'Полковник',
],
];
$params = [
'prompt' => 'Выберите статус...',
];
echo $form->field($model, 'hit')->dropDownList($items,$params);
?>
<!-- Выпадающий список-->
<?= DetailView::widget([
'model' => $model,
'attributes' => [
// 'id',
// 'category_id',
[
'attribute' => 'category_id',
'value' => function ($data) {
return $data->category->name;
},
],
'name',
'date',
'content:html',
'dolzhnost',
'datestart',
'dateend',
// 'price',
'keywords:html',
'description:html',
[
'attribute' => 'image',
'value' => "<img src='{$img->getUrl()} '>",
'format' => 'html',
],
'hit:html', //modules/admin/views/product/view.php 54 строка
'year',
],
]) ?>
<p><b>Звание: </b><?= $product->hit?></p>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question