0

My demo code is given below. My method returns data from database and on that value how i show it checked or not

<?php
$notf_col = [
    "1" => 'User Create',
    "2" => 'User Update',
];

$check_data = NotificationChecklist::getCheckList(Yii::$app->user->identity->id);
//check data will hold ["1","2"]
if (!empty($check_data)) {
    $checkedList = $check_data; //get selected value from db if value exist
    $model->notf_action_col = $checkedList;
}
?>

<div class="notification-checklist-form">
    <?php $form = ActiveForm::begin(['action' => 'notification-checklist/create',]); ?>
    <?= $form->field($model, 'notf_action_col')->checkboxList($notf_col)->label(FALSE) ?>
    <div class="form-group">
        <?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
    </div>
    <?php ActiveForm::end(); ?>
</div>
Destroyer.0211
  • 113
  • 1
  • 3
  • 13

0 Answers0