Yii radioButtonList具有listData和html数据属性


Yii radioButtonList with listData and html data attribute

我正在尝试输出CHtml::radioButtonList(yii 1.1.14),每个渲染的元素看起来如下:

<input id="option_0" type="radio" name="MyForm[customOption_id]" value="1" data-ref="a string contained in table, column ref">
<label for="option_0">Some option</label>

让我头疼的是data-ref属性。

代码

<li>
<?php 
echo $form->radioButtonList(
        $model,'refinement_id',
        CHtml::listData($refinements, 'id', 'label'),
        array('separator'=>'</li><li>', 'container' => '')); 
?>
</li>

我想为每一个输出一个data-ref属性,然后我可以在一些JavaScript中使用它。

据我所知,我不能将其添加到radioButtonList的htmlOptions数组中,因为我只能在这里提供一个静态值。

如果有人告诉我我找错树了,我将不胜感激。

数据引用的内容取决于值还是静态?如果它不是静态的,使用$form->radioButtonList是不可能的,那么用老式的方法来做。否则就是简单的

<?php 
echo $form->radioButtonList(
    $model,'refinement_id',
    CHtml::listData($refinements, 'id', 'label'),
    array('separator'=>'</li><li>', 'container' => '', 'data-ref'=>'fshafh')); 
?>