I use the Yii2 structure and I would like to generate html code like this
<input type="checkbox" id="queue-order" name="Queue[order]" value="1" checked>
in a view that uses ActiveForm.
I tried
echo $form->field($model, 'order') ->checkBox(['label' => ..., 'uncheck' => null, 'checked' => true]);
and
echo $form->field($model, 'order') ->checkBox(['label' => ..., 'uncheck' => null, 'checked' => 'checked']);
but the desired "checked" line is not displayed in the generated HTML code.
Oddly enough, if you replace "checked" with "selected"
echo $form->field($model, 'order') ->checkBox(['label' => ..., 'uncheck' => null, 'selected' => true]);
then the generated html code contains the attribute "selected":
<input type="checkbox" id="queue-order" name="Queue[order]" value="1" selected>
So, how can I generate html code for a flag with the attribute "checked"?
source share