I’am a beginner with Yii2 and found my-self in trouble with simple task: how to retrieve table data via POST request?
My code:
<?=Html::beginForm(['list-profile/index'], 'get', ['data-pjax' => '', 'class' => 'form-inline', 'id' => 'list-channels-groups']);?>
<?=Html::DropDownList('name', $getChannelGroups[0]->name,
ArrayHelper::map(\app\models\ListChannelsGroups::find()->asArray()->all(), 'id', 'name'), ['class' => 'form-control', 'prompt' => Yii::t('app', '--Choose channel list group--'), 'onchange'=>'this.form.submit()'])
?>
<?php if (Yii::$app->request->get('name')) : ?>
<span class="pull-right">
<?=Html::a(Yii::t('app', 'Add all channels'), ['addall', 'name' => Yii::$app->request->get('name')], ['class' => 'btn btn-success'])?>
<?=Html::a(Yii::t('app', 'Remove all channels'), ['delall', 'name' => Yii::$app->request->get('name')], ['class' => 'btn btn-danger'])?>
<?=Html::a(Yii::t('app', 'Resort channels'), ['resort', 'name' => Yii::$app->request->get('name')], ['class' => 'btn btn-warning'])?>
</span>
<?=Html::endForm();?>
<?php endif; ?>
<!-- Select profile list group END -->
<br>
<?=GridView::widget([
'id' => 'list-channels',
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'rowOptions' => function ($model) {
if (strtotime($model->date_start) > strtotime("now")) {
return ['class' => 'info'];
} else if ($model->date_end == null) {
return ['class' => 'success'];
} else if (strtotime($model->date_end) < strtotime("now")) {
return ['class' => 'warning'];
}
},
'pager' => [
'firstPageLabel' => Yii::t('app', 'First'),
'lastPageLabel' => Yii::t('app', 'Last'),
],
'columns' => [
[
'label'=>'#',
'attribute' => 'channel.sort',
'value' => 'channel.sort',
],
[
'label'=>'Sort No.',
'attribute'=>'no',
'format' => 'raw',
'value'=> function ($data) {
return Html::textInput("sortOrder$data->no",$data->no,array("style"=>"width:40px;"));
},
],
[
'attribute' => 'channel.name',
'format' => 'raw',
'value' => function ($data) {
return Html::a($data->getChannelName($data->channel_id), ['update', 'id' => $data->id, 'name' => Yii::$app->request->get('name')], ['data-pjax' => 0]);
},
],
'create_time',
'update_time',
['class' => 'yii\grid\ActionColumn',
'template' => '{remove}',
'buttons' => [
'remove' => function ($url, $model, $key) {
return Html::a('<span class="glyphicon glyphicon-remove text-danger"></span>', ['list-profile/index', 'rem_id' => $model->id, 'name' => Yii::$app->request->get('name')], ['title' => Yii::t('app', 'Remove from profile'),
]
);
}
],
'contentOptions' => ['style' => 'min-width: 50px;text-align: center;'],
]
],
]);?>
</div>
<?php endif; ?>
<?php Pjax::end(); ?>
At the top of code snippet you see buttons, one of them is “Resort channels”. How to do, that when I press that button, all data from table be POSTed into my controller for further operations? This looks like very simple task in plain PHP (wrap in form with hidden inputs), but with Yii2 this is insanely complex and I simply stuck.