Responsive Ad Area

Share This Post


YII2 insert data from CheckBoxList

In my Form :

 <?= GridView::widget([
 'id' => 'griditems',
 'dataProvider' => $dataProvider,
  'columns' => [
   ['class' => 'yiigridCheckboxColumn'],

]); ?>

In my Controller :

public function actionCreate()
    $model = new Package();
    $searchModel = new ShipmentSearch();
    $searchModel->shipment_position=1; // الشحنه في مقر الشركة
    $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

    if ($model->loadAll(Yii::$app->request->post())){ 
        $select = Yii::$app->request->post('selection');

        foreach($select as $id){
            $shipment= shipment::findOne((int)$id);

        return $this->redirect(['view', 'id' => $model->id]);
    } else {
        return $this->render('create', [
            'model' => $model,

I just try this way to insert data as above its works but the data inserted just last one or last CheckBox from the list . I tried to print the id that in foreach and there is more than one id

YII2 insert data from CheckBoxList
YII2 insert data from CheckBoxList

Share This Post

Leave a Reply

Your email address will not be Publishedd. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Skip to toolbar