Extends
lithium\template\Helper
Generates an HTML `<input type="checkbox" />` object.
Parameters
- string $name The name of the field.
- array $options Options to be used when generating the checkbox `<input />` element: - `'checked'` _boolean_: Whether or not the field should be checked by default. - `'value'` _mixed_: if specified, it will be used as the 'value' html attribute and no hidden input field will be added. - Any other options specified are rendered as HTML attributes of the element.
Returns
string Returns a `<input />` tag with the given name and HTML attributes.Source
public function checkbox($name, array $options = array()) {
$defaults = array('value' => '1', 'hidden' => true);
$options += $defaults;
$default = $options['value'];
$key = $name;
$out = '';
list($name, $options, $template) = $this->_defaults(__FUNCTION__, $name, $options);
list($scope, $options) = $this->_options($defaults, $options);
if (!isset($options['checked']) && ($bound = $this->binding($key)->data)) {
$options['checked'] = ($bound == $default);
}
if ($scope['hidden']) {
$out = $this->hidden($name, array('value' => '', 'id' => false));
}
$options['value'] = $scope['value'];
return $out . $this->_render(__METHOD__, $template, compact('name', 'options'));
}