yii\helpers\BaseHtml::activeBooleanInput PHP Method

activeBooleanInput() protected static method

Generates a boolean input This method is mainly called by BaseHtml::activeCheckbox and BaseHtml::activeRadio.
Since: 2.0.9
protected static activeBooleanInput ( string $type, Model $model, string $attribute, array $options = [] ) : string
$type string the input type. This can be either `radio` or `checkbox`.
$model yii\base\Model the model object
$attribute string the attribute name or expression. See [[getAttributeName()]] for the format about attribute expression.
$options array the tag options in terms of name-value pairs. See [[booleanInput()]] for details about accepted attributes.
return string the generated input element
    protected static function activeBooleanInput($type, $model, $attribute, $options = [])
    {
        $name = isset($options['name']) ? $options['name'] : static::getInputName($model, $attribute);
        $value = static::getAttributeValue($model, $attribute);
        if (!array_key_exists('value', $options)) {
            $options['value'] = '1';
        }
        if (!array_key_exists('uncheck', $options)) {
            $options['uncheck'] = '0';
        }
        if (!array_key_exists('label', $options)) {
            $options['label'] = static::encode($model->getAttributeLabel(static::getAttributeName($attribute)));
        }
        $checked = "{$value}" === "{$options['value']}";
        if (!array_key_exists('id', $options)) {
            $options['id'] = static::getInputId($model, $attribute);
        }
        return static::$type($name, $checked, $options);
    }