Answer the question
In order to leave comments, you need to log in
Create checkboxlist, write or update, value 1 and 0 in db?
Hello. I can't solve the problem with checkboxlist. the display is ok.
view:
<?php $form = ActiveForm::begin([
'id' => 'form-input-example',
],
]) ?>
<?= $form->field($model, 'status_id')
->checkboxList(ArrayHelper::map(Blog::find()->all(), 'id', 'status_id')) ?>
<?= Html::submitButton('Сохранить', ['class' => 'btn btn-primary']) ?>
<?php ActiveForm::end(); ?>
public function actionTests()
{
$model = new Blog();
$model->status_id = Blog::find()->where('status_id')->all();
if ($model->load(Yii::$app->request->post()) && $model->save())
{
// Сделать что-то после записи, например SetFlash
}
return $this->render('tests', [
'model' => $model,
]);
}
public function rules()
{
return [
['status_id', 'safe'],
];
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question