Php 如何在yii2中的radioList()中添加不同的通用类

Php 如何在yii2中的radioList()中添加不同的通用类,php,arrays,yii2,yii2-model,Php,Arrays,Yii2,Yii2 Model,这是我的一个更新表单中的chtml单选按钮 <?= $form->field($model, 'customer_sel')->radioList(array('customer' => 'Customer', 'supplier' => 'Supplier', 'excludecustomer' => 'Exclude Customer', 'all' => 'All'))->label('Select Choice'); ?> 我

这是我的一个更新表单中的chtml单选按钮

 <?= $form->field($model, 'customer_sel')->radioList(array('customer' => 'Customer', 'supplier' => 'Supplier', 'excludecustomer' => 'Exclude Customer', 'all' => 'All'))->label('Select Choice'); ?>

我需要为每个无线电输入添加公共(相同)和不同类的类名。 这就是它在html中的外观

 <div class="form-group field-cashbankentry-customer_sel">
<label class="control-label" for="cashbankentry-customer_sel">Select Choice</label>
<input type="hidden" name="CashBankentry[customer_sel]" value=""><div id="cashbankentry-customer_sel"><label><input type="radio" class="inputbox inputindex_1" name="CashBankentry[customer_sel]" value="customer" checked> Custom</label>
<label><input type="radio" class="inputbox inputindex_2 name="CashBankentry[customer_sel]" value="supplier"> Supplier</label>
<label><input type="radio" class="inputbox inputindex_3 name="CashBankentry[customer_sel]" value="excludecustomer"> Exclude Customer</label>
<label><input type="radio" class="inputbox inputindex_4 name="CashBankentry[customer_sel]" value="all"> All</label></div>

选择
习俗
排除客户

我认为,如果不使用
$form->field()
帮助程序生成标记,会更容易。检查它的实现,您将看到需要单独编写代码的不同部分


调用
$form->field()
基本上调用
Html::activeLabel()
Html::activeInput()
Html::activeError()
您需要为
radioList
选项配置
选项,有关详细信息,请参见

下面的代码应该适合您

<?php echo $form->field($model, 'customer_sel')->radioList(
        [
            'customer' => 'Customer',
            'supplier' => 'Supplier',
            'excludecustomer' => 'Exclude Customer',
            'all' => 'All',
        ],
        [
            'item' => function ($index, $label, $name, $checked, $value) {

                $return = '<label>';
                $return .= '<input class="inputbox inputindex_' . (++$index) . '" type="radio" name="' . $name . '" value="' . $value . '" ' . ($checked ? "checked" : "") . '>';
                $return .= ucwords($label);
                $return .= '</label>';
                return $return;
            },

        ]
    )->label('Select Choice');
?>

嗨,奥马尔-我想我分享了一个错误的链接-这里是正确的链接-
<?php echo $form->field($model, 'customer_sel')->radioList(
        [
            'customer' => 'Customer',
            'supplier' => 'Supplier',
            'excludecustomer' => 'Exclude Customer',
            'all' => 'All',
        ],
        [
            'item' => function ($index, $label, $name, $checked, $value) {

                $return = '<label>';
                $return .= '<input class="inputbox inputindex_' . (++$index) . '" type="radio" name="' . $name . '" value="' . $value . '" ' . ($checked ? "checked" : "") . '>';
                $return .= ucwords($label);
                $return .= '</label>';
                return $return;
            },

        ]
    )->label('Select Choice');
?>
$model = new CashBankentry();
$model->customer_sel='customer';