yii2单选按钮中缺少id属性

yii2单选按钮中缺少id属性,yii2,Yii2,我在使用yii2动态表单包时遇到了yii2单选按钮的一个问题。Yi2未生成id属性为的单选按钮。由于单选按钮中缺少id属性,yii2动态表单单选按钮值始终设置为1。所以请帮助我如何克服这个问题 已编辑 <?= $form->field($client_allow_acces, "[$i]access_type")->radioList([1 => 'Allow access', 2 => 'Can\'t allow access'], ['uncheckValue'

我在使用yii2动态表单包时遇到了yii2单选按钮的一个问题。Yi2未生成id属性为的单选按钮。由于单选按钮中缺少id属性,yii2动态表单单选按钮值始终设置为1。所以请帮助我如何克服这个问题

已编辑

<?= $form->field($client_allow_acces, "[$i]access_type")->radioList([1 => 'Allow access', 2 => 'Can\'t allow access'], ['uncheckValue' => null, 'id'=>'custom_id_value']) ?>

我得到下面的html输出

<div class="form-group field-clientallowaccess-0-access_type required">
    <label class="control-label" for="custom_id_value">Access Type</label>
    <input type="hidden" name="ClientAllowAccess[0][access_type]" value="">
    <div id="custom_id_value">
        <label><input type="radio" name="ClientAllowAccess[0][access_type]" value="1"> Allow access</label>
        <label><input type="radio" name="ClientAllowAccess[0][access_type]" value="2"> Can't allow access</label>
    </div>
    <div class="help-block"></div>
</div>

访问类型
允许访问
无法允许访问
我的自定义id值位于div元素中。但我需要单选按钮本身


提前感谢。

您需要使用以下代码,因为您的给定id已分配给代码中的
div
。那是在

<?= $form->field($client_allow_acces, '[$i]access_type')->radioList([1 => 'Allow access', 2 => 'Can\'t allow access'],[ 'item' => function($index, $label, $name, $checked, $value) {
                                    $return = '<label class="modal-radio">';
                                    $return .= '<input type="radio" name="' . $name . '" value="' . $value . '" id="custom_id_value_'.$index.'" >';
                                    $return .= '<span>  ' . ucwords($label) . '</span>';
                                    $return .= '</label>';
                                    return $return;
                             }]); ?> 

显示您的相关代码…@scaisEdge感谢您的回复。我编辑了我的问题。请现在检查。