TbHtml::activeRadioButtonList PHP Method

activeRadioButtonList() public static method

Generates a radio button list for a model attribute.
public static activeRadioButtonList ( CModel $model, string $attribute, array $data, array $htmlOptions = [] ) : string
$model CModel the data model.
$attribute string the attribute.
$data array $data value-label pairs used to generate the radio button list.
$htmlOptions array additional HTML attributes.
return string the generated list.
    public static function activeRadioButtonList($model, $attribute, $data, $htmlOptions = array())
    {
        parent::resolveNameID($model, $attribute, $htmlOptions);
        $selection = parent::resolveValue($model, $attribute);
        $name = TbArray::popValue('name', $htmlOptions);
        $uncheckValue = TbArray::popValue('uncheckValue', $htmlOptions, '');
        $hiddenOptions = isset($htmlOptions['id']) ? array('id' => parent::ID_PREFIX . $htmlOptions['id']) : array('id' => false);
        $hidden = $uncheckValue !== null ? parent::hiddenField($name, $uncheckValue, $hiddenOptions) : '';
        return $hidden . self::radioButtonList($name, $selection, $data, $htmlOptions);
    }

Usage Example

 /**
  * Renders a radio button list for a model attribute
  * @param CModel $model the data model.
  * @param string $attribute the attribute.
  * @param array $data data for generating the list options (value=>display)
  * @param array $htmlOptions additional HTML attributes.
  * @return string the generated radio button list.
  * @see TbHtml::activeRadioButtonList
  */
 public function radioButtonList($model, $attribute, $data, $htmlOptions = array())
 {
     return TbHtml::activeRadioButtonList($model, $attribute, $data, $htmlOptions);
 }
All Usage Examples Of TbHtml::activeRadioButtonList
TbHtml