How to pre select radioButtonListRow and checkboxListRow with Yii 2
Looking at the code in Yii for radioButtonListRow and checkboxListRow it’s not apparent how to preselect these form elements with previously selected data.
<?php echo $form->checkboxListRow($model, 'id', CHtml::listData(models\web_data\Program::model()->findAll(array('order' => 'name')), 'id', 'name')); ?> |
The solution is to set the model’s property to your selected values in the controller. You can use a scalar value or an array of values. For the above line of code, we can use the below –
$model->id = array(2,3); |
or
$model->id = 2; |