2014-04-16 23 views
0

我试图输出了CHtml ::单选按钮列表(警予1.1.14),每个渲染元素看起来像如下:Yii的单选按钮列表用的ListData和HTML数据属性

<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> 

它是数据-ref属性这让我很头疼。

代码

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

我要输出为每个我然后可以在一些JavaScript使用数据-ref属性。

据我可以告诉我不能将此添加到radioButtonList的htmlOptions数组,因为我只能在这里提供一个静态值。

任何指针在这里或有人告诉我我吠错了树会非常感激。

回答

1

data-ref的内容取决于值或静态?如果它不是静态的,使用$ form-> radioButtonList是不可能的,那么用老派的方法来做。否则很简单

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

取决于'$ refinements'中的实例。好的谢谢。只需要知道是否可以使用Yii小部件。 – Tomeh