Sunday, 1 April 2012

Yii framework: Generate RadioButtonList

The following code:


echo CHtml::RadioButtonList('id', '', array('Male'=>'Male','Female'=>'Female'));


will generate:


<input value="Male" id="id_0" type="radio" name="id">
<label for="id_0">Male</label>
<br>
<input value="Female" id="id_1" type="radio" name="id">
<label for="id_1">Female</label>


Other tricks:


Display them inline without '<br>' separator:



echo CHtml::RadioButtonList('id', '', array('Male'=>'Male','Female'=>'Female'), 
array('labelOptions'=>array('style'=>'display:inline'), separator'=>''));

No comments:

Post a Comment