Php 在Yii2中使用带ActiveField的radioList方法为每个无线盒子提供不同的选项
我正在使用ActiveField小部件中的方法,并且我正在尝试解决如何为同一列表中的不同广播框设置不同的选项 我有这个Php 在Yii2中使用带ActiveField的radioList方法为每个无线盒子提供不同的选项,php,yii,yii2,Php,Yii,Yii2,我正在使用ActiveField小部件中的方法,并且我正在尝试解决如何为同一列表中的不同广播框设置不同的选项 我有这个 $form->field($model, 'some_question')->inline()->radioList( [ 1 => Yii::t('general', 'Yes'), 0 => Yii::t('general', 'No') ], ['itemOptions' => [
$form->field($model, 'some_question')->inline()->radioList(
[
1 => Yii::t('general', 'Yes'),
0 => Yii::t('general', 'No')
],
['itemOptions' => ['value' => 1, 'data-foo' => 'bar']]
)->label(false);
但是,无论我在
itempoptions
中设置了什么,都会在所有单选按钮上设置—是否有方法为每个按钮设置不同的值?为此,请使用可调用的item
$form->field($model, 'some_question')->inline()->radioList(
[
1 => Yii::t('general', 'Yes'),
0 => Yii::t('general', 'No')
],
['item' => function ($index, $label, $name, $checked, $value) {
switch ($value) {
// different options per value
case 1:
$options = [
'data-foo' => 'bar'
];
break;
case 0:
$options = [
'data-next' => 'smthng'
];
}
return \yii\bootstrap\Html::radio($name, $checked, array_merge($options, [
'value' => $value,
'label' => \yii\bootstrap\Html::encode($label),
]));
}]
)->label(false);