My problem is when I select data from the check box and click save button, I do not know where it goes. Do I need to make another table or add column in events table.
This is the coding for index.php for events.
<?php
use yii\helpers\Html;
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Events';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="events-index">
<h1><?= Html::encode($this->title) ?></h1>
<p>
<?= Html::a('Create Events', ['create'], ['class' => 'btn btn- success']) ?>
</p>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'event_title',
'event_date',
'event_location:ntext',
['class' => 'yii\grid\ActionColumn'],
['class' => 'yii\grid\CheckBoxColumn'],
],
]); ?>
<?=Html::beginForm(['events/bulk'],'post');?>
<center><?=Html::submitButton('Save', ['class' => 'btn btn-info',]);?> </center>
<?= Html::endForm();?>
</div>
This is the code for action bulk in eventscontroller.php . I'm new in yii2, so I dont know how to edit this following code so that when I click the save button after select event it will save to the database.
public function actionBulk()
{
$selection=(array)Yii::$app->request->post('selection');//typecasting
foreach($selection as $id){
$e=Events::findOne((int)$id);//make a typecasting
//do your stuff
$e->save();
}
}
Hope that someone can help me to fix the problem. I'm really appreciate it. Thank you.