lithium\template\helper\Form::radio()

public method

Generates an HTML <input type="radio" /> object.

Parameters

  • string $name

    The name of the field

  • array $options

    All options to be used when generating the radio <input /> element:

    • 'checked' boolean: Whether or not the field should be selected by default.
    • 'value' mixed: if specified, it will be used as the 'value' html attribute. Defaults to 1
    • Any other options specified are rendered as HTML attributes of the element.

Returns

string

Returns a <input /> tag with the given name and attributes

Source

	public function radio($name, array $options = []) {
		$defaults = ['value' => '1'];
		$options += $defaults;
		$default = $options['value'];
		$key = $name;

		list($name, $options, $template) = $this->_defaults(__FUNCTION__, $name, $options);
		list($scope, $options) = $this->_options($defaults, $options);

		if (!isset($options['checked'])) {
			$options['checked'] = ($this->binding($key)->data == $default);
		}

		$options['value'] = $scope['value'];
		return $this->_render(__METHOD__, $template, compact('name', 'options'));
	}