未知方法 - Yii2中的ActiveField :: radioButtonList()

时间:2022-10-05 09:34:41

I want to display RadioButton List in form.

我想在表单中显示RadioButton List。

I tried using below code:

我尝试使用以下代码:

<?php
$list = [0 => 'Morning', 1 => 'Noon', 2 => 'Evening'];

/* Display a stacked checkbox list */
echo $form->field($model, 'is_active')->radioButtonList($list);
?>

But I got error below:

但我得到以下错误:

Unknown Method – yii\base\UnknownMethodException
Calling unknown method: yii\widgets\ActiveField::radioButtonList()

2 个解决方案

#1


Try:

 $list = [0 => 'Morning', 1 => 'Noon', 2 => 'Evening'];
 echo $form->field($model, 'is_active')->radioList($list); 

#2


Maybe this helps:

也许这有助于:

<?= $form->field($ShipmentTypeForm, 'shipmenttype')
         ->radioList(['radio1'=>'radio1','radio2'=>'radio2'],['class'=>'your_class','id'=>'your_id']); ?>

#1


Try:

 $list = [0 => 'Morning', 1 => 'Noon', 2 => 'Evening'];
 echo $form->field($model, 'is_active')->radioList($list); 

#2


Maybe this helps:

也许这有助于:

<?= $form->field($ShipmentTypeForm, 'shipmenttype')
         ->radioList(['radio1'=>'radio1','radio2'=>'radio2'],['class'=>'your_class','id'=>'your_id']); ?>