Thursday, 13 August 2015

CheckboxList Advanced Operations

Yii2.0 CheckboxList items as checked as the form loads?

 HTML Helper checkboxlist

Method of check boxes to be checked as the form loads.

$list = [0 => 'PHP', 1 => 'MySQL', 2 => 'Javascript'];

$list2 = [0,2];

using the following line

<?= Html::checkboxList('CuisineId',$list2,$list); ?>

Output as above and below codes 

Other Way:

Just to add the following line of codes

$record->CuisineId = $list2;
<?= $form->field($record, 'CuisineId')->checkboxlist($list);?> 

No comments:

Post a Comment