sukran
(Skeeran)
1
Hallo,
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);
if($model->save())
{
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.
sukran
(Skeeran)
3
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.
sukran
(Skeeran)
5
i made php display_errors = on
still having same blank page
Is there any information in webserver logs?
sukran
(Skeeran)
8
Thank you ORey,
now its working i didn’t changed anything 
sukran
(Skeeran)
9
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 
_form
<?= $form->field($model, 'sprachen')->checkboxList(ArrayHelper::map(Sprachen::find()->all(), 'name', 'name'),['inline'=>true]);?>
Controller
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post())){
$model->sprachen = implode(",", $model->sprachen);
if($model->save()){
return $this->redirect(['view', 'id' => $model->id]);
}
} else {
$model->sprachen = explode(',',$model->sprachen);
return $this->render('update', [
'model' => $model,
]);
}
}
Magic!

PS. probably cached schema, check config settings.