samedi 18 février 2023

Yii2 Using Multiple Checkbox Fields

I have a Yii2 app in which I want to use multiple checkbox as array. The checkbox is part of my Model, but it's not a DB column. It also has a custom value.

I loop through a list of days, set a custom value for the checkboxes and print the checkboxes to my view like this:

echo $form->field($model, 'dayIds[]')->checkbox(
            ['value' => $day->id.'_'.$person->id])->label(false);

On my Model side I have this:

public $dayIds;

foreach ($this->dayIds as $dayId) {
     //do something
}

I have tried many different scenarios but always end up with error on my Model that $this->dayIds is null.

Any ideas please?




Aucun commentaire:

Enregistrer un commentaire