src/Helpers/Form.php
public function generateRadioField($attr)
    {
        if (empty($attr['name'])) {
            return '';
        }

        $out = '';

        $options = array();
        if (! empty($attr['options'])) {
            $options = $attr['options'];
        }

        if (isset($attr['checked'])) {
            $checkedItem = $attr['checked'];
        }

        unset($attr['options'], $attr['checked']);

        foreach ($options as $value => $label) {
            $id = $attr['id'] . '_' . $value;

            $optionsAttr = array('id' => $id, 'value' => $value);
            if (isset($checkedItem) && $checkedItem == $value) {
                $optionsAttr[] = 'checked';
            }
            $input = $this->Html->tag(
                'input',
                array_merge(
                    $attr,
                    $optionsAttr
                )
            );

            $label = $this->Html->tag(
                'label',
                array('for' => $id),
                $label,
                true
            );

            $out .= $this->Html->tag(
                'div',
                array(
                    'class' => 'radio-item'
                ),
                $input . $label,
                true
            );
        }

        return $out;
    }
public function generateRadioField($attr)
    {
        if (empty($attr['name'])) {
            return '';
        }

        $out = '';

        $options = array();
        if (! empty($attr['options'])) {
            $options = $attr['options'];
        }

        if (isset($attr['checked'])) {
            $checkedItem = $attr['checked'];
        }

        unset($attr['options'], $attr['checked']);

        foreach ($options as $value => $label) {
            $id = $attr['id'] . '_' . $value;

            $optionsAttr = array('id' => $id, 'value' => $value);
            if (isset($checkedItem) && $checkedItem == $value) {
                $optionsAttr[] = 'checked';
            }
            $input = $this->Html->tag(
                'input',
                array_merge(
                    $attr,
                    $optionsAttr
                )
            );

            $label = $this->Html->tag(
                'label',
                array('for' => $id),
                $label,
                true
            );

            $out .= $this->Html->tag(
                'div',
                array(
                    'class' => 'radio-item'
                ),
                $input . $label,
                true
            );
        }

        return $out;
    }
public function generateRadioField ( $ attr ) { if ( empty ( $ attr [ 'name' ] ) ) { return '' ; } $ out = '' ; $ options = array ( ) ; if ( ! empty ( $ attr [ 'options' ] ) ) { $ options = $ attr [ 'options' ] ; } if ( isset ( $ attr [ 'checked' ] ) ) { $ checkedItem = $ attr [ 'checked' ] ; } unset ( $ attr [ 'options' ] , $ attr [ 'checked' ] ) ; foreach ( $ options as $ value => $ label ) { $ id = $ attr [ 'id' ] . '_' . $ value ; $ optionsAttr = array ( 'id' => $ id , 'value' => $ value ) ; if ( isset ( $ checkedItem ) && $ checkedItem == $ value ) { $ optionsAttr [ ] = 'checked' ; } $ input = $ this -> Html -> tag ( 'input' , array_merge ( $ attr , $ optionsAttr ) ) ; $ label = $ this -> Html -> tag ( 'label' , array ( 'for' => $ id ) , $ label , true ) ; $ out .= $ this -> Html -> tag ( 'div' , array ( 'class' => 'radio-item' ) , $ input . $ label , true ) ; } return $ out ; }
generate a selection of radio buttons

@param   array   array of attributes
@return  string
generate a selection of radio buttons