Reputation: 510
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?
Upvotes: 0
Views: 149
Reputation: 634
The array variable dayIds[]
and scalar variable $dayIds
are two different variables. You can define dayIds1
, dayIds2
, etc. or alternatively dayIds[1]
, dayIds[2]
, etc.
Basically, I don't see $this->dayIds
being assigned anything - so it will always be null.
Upvotes: 0