yii\helpers\BaseHtml::input PHP Метод

input() публичный статический Метод

Generates an input type of the given type.
public static input ( string $type, string $name = null, string $value = null, array $options = [] ) : string
$type string the type attribute.
$name string the name attribute. If it is null, the name attribute will not be generated.
$value string the value attribute. If it is null, the value attribute will not be generated.
$options array the tag options in terms of name-value pairs. These will be rendered as the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]]. If a value is null, the corresponding attribute will not be rendered. See [[renderTagAttributes()]] for details on how attributes are being rendered.
Результат string the generated input tag
    public static function input($type, $name = null, $value = null, $options = [])
    {
        if (!isset($options['type'])) {
            $options['type'] = $type;
        }
        $options['name'] = $name;
        $options['value'] = $value === null ? null : (string) $value;
        return static::tag('input', '', $options);
    }

Usage Example

Пример #1
0
 public static function input($type = '', $model, $attribute, $labels, $options = [], $errors = [])
 {
     $type = $type == '' ? 'text' : $type;
     if (empty($options)) {
         $options = ['class' => 'form-control'];
     }
     $value = is_object($model) && isset($model->{$attribute}) ? $model->attribute : '';
     $html = '<div class="form-group">';
     $html .= '<label class="control-label">' . (isset($labels[$attribute]) ? $labels[$attribute] : '') . '</label><br>';
     $html .= parent::input($type, $attribute, $value, $options);
     $html .= self::errorBlock(isset($errors[$attribute]) ? $errors[$attribute] : []);
     $html .= '</div>';
     return $html;
 }