Answer the question
In order to leave comments, you need to log in
How to display data from Widget in Html::dropDownList?
Tell me how can I pass a menu with categories that are in the widget (called MenuWidget).
The widget creates a tree menu based on the database, and generates an html template for output.
I need to transfer this widget with categories to dropDownList in order to implement mass transfer of articles. I will transfer to any of them and I need to know which one to transfer to. Accordingly, you need: Value (this is the 'id' field) and the name of the category ('name').
<?=Html::beginForm(['posts/bulk'],'post',['class' => 'form-group']);?><br>
<?=Html::dropDownList('action','',[c'=>'Confirmed',
// Вот сюда нужно как то вывести
])?>
<?=Html::submitButton('Сохранить', ['class' => 'btn btn-warning btn-xs',]);?><br><br>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
[ 'class' => yii\grid\CheckboxColumn::className(),],
'id',
'name',
...
'description',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
<?= Html::endForm();?>
<?=Html::dropDownList('action','',[ ''=>'Категория из меню: ',
app\components\MenuWidget::widget(['tpl' => 'select_book', 'model' => $model])
])?>
<option value="<?=$category['id'] ?>"
<? if($category['id'] == $this->model->category_id) echo ' selected' ?>>
<?=$tab . $category['name'] ?>
</option>
<?php if(isset($category['childs']) ): ?>
<?=$this->getMenuHtml($category['childs'], $tab . ' - ') ?>
<?php endif;?>
<select class="form-control " name="action">
<option value="0">
<option value="1">Название 1</option>
...
<option value="1">Название 10</option>
</option>
</select>
Answer the question
In order to leave comments, you need to log in
Good evening.
Here are two examples from the official documentation
<?= Html::dropDownList('list', $currentUserId, ArrayHelper::map($userModels, 'id', 'name')) ?>
<?= Html::activeDropDownList($users, 'id', ArrayHelper::map($userModels, 'id', 'name')) ?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question