Checkboxlist Value Store Db


i wana get a list of checkboxlist values and save it into my database like this : en,fr,sp,it

my code is like:


<?php $list = ["en" => 'EN', "fr" => 'FR', "it" => 'IT', "sp" => 'SP'];?>


<?= $form->field($model, 'sprachen')->checkboxList($list,['inline'=>true]);?>

when i save i get error the value must be String so i tryed to implode like this in Update/Create actions.

if ($model->load(Yii::$app->request->post()))



       $model->sprachen = implode(",", $model->sprachen);




	      return $this->redirect(['mylistingdetail', 'id' => $model->id]);



now when i save i get a blank page. Can anyone one help me

Blank page usually means php error, turn error displaying on and you’ll see what’s actually happening. Also check webserver logs.

PS. Btw your code style is not following PSR-2 that is a standard for Yii2.

thanks for prompt answer, i am on learning process…

how can this be done in PSR-2 code style ?

But that’s not what the question was on.

Check your php.ini and see if

display_errors = On

You can use phpinfo(); to see current error settings.

i made php display_errors = on

still having same blank page

Is there any information in webserver logs?


Thank you ORey,

now its working i didn’t changed anything :blink:

Made some Modification so its getting the data from Database

posting my code maybe someone may found it useful.

if you guys know better and eleganter way to do this, please suggest it, then i can learn :rolleyes:


<?= $form->field($model, 'sprachen')->checkboxList(ArrayHelper::map(Sprachen::find()->all(), 'name', 'name'),['inline'=>true]);?>


    public function actionUpdate($id)


        $model = $this->findModel($id);


        if ($model->load(Yii::$app->request->post())){


			$model->sprachen = implode(",", $model->sprachen);



				return $this->redirect(['view', 'id' => $model->id]);



        } else {

        	$model->sprachen = explode(',',$model->sprachen);

            return $this->render('update', [

                'model' => $model,





PS. probably cached schema, check config settings.