如何在yii2 RadioList()中预选/检查默认单选按钮?

Ins*_*ull 8 html php yii2 active-form

我希望在我的表单中预先选择单选按钮.

 <?= $form->field($model, 'config')->radioList(['1'=>'Automatic Entry',2=>'Manual Entry'])
     ->label('Barcode/Book No Generation'); ?>
Run Code Online (Sandbox Code Playgroud)

tar*_*leb 22

预选值取自$model->config.这意味着您应该将该属性设置为您想要预选的值:

$model->config = '1';
$form->field($model, 'config')->radioList([
    '1' => 'Automatic Entry',
    '2' => 'Manual Entry',
]);
Run Code Online (Sandbox Code Playgroud)

相关文档是在ActiveForm类中.