Cake\View\Helper\FormHelper::input PHP Метод

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

### Options See each field type method for more information. Any options that are part of $attributes or $options for the different **type** methods can be included in $options for input(). Additionally, any unknown keys that are not in the list below, or part of the selected type's options will be treated as a regular HTML attribute for the generated input. - type - Force the type of widget you want. e.g. type => 'select' - label - Either a string label, or an array of options for the label. See FormHelper::label(). - options - For widgets that take options e.g. radio, select. - error - Control the error message that is produced. Set to false to disable any kind of error reporting (field error and error messages). - empty - String or boolean to enable empty select box options. - nestedInput - Used with checkbox and radio inputs. Set to false to render inputs outside of label elements. Can be set to true on any input to force the input inside the label. If you enable this option for radio buttons you will also need to modify the default radioWrapper template. - templates - The templates you want to use for this input. Any templates will be merged on top of the already loaded templates. This option can either be a filename in /config that contains the templates you want to load, or an array of templates to use.
public input ( string $fieldName, array $options = [] ) : string
$fieldName string This should be "modelname.fieldname"
$options array Each type of input takes different options.
Результат string Completed form widget.
    public function input($fieldName, array $options = [])
    {
        $options += ['type' => null, 'label' => null, 'error' => null, 'required' => null, 'options' => null, 'templates' => [], 'templateVars' => []];
        $options = $this->_parseOptions($fieldName, $options);
        $options += ['id' => $this->_domId($fieldName)];
        $templater = $this->templater();
        $newTemplates = $options['templates'];
        if ($newTemplates) {
            $templater->push();
            $templateMethod = is_string($options['templates']) ? 'load' : 'add';
            $templater->{$templateMethod}($options['templates']);
        }
        unset($options['templates']);
        $error = null;
        $errorSuffix = '';
        if ($options['type'] !== 'hidden' && $options['error'] !== false) {
            if (is_array($options['error'])) {
                $error = $this->error($fieldName, $options['error'], $options['error']);
            } else {
                $error = $this->error($fieldName, $options['error']);
            }
            $errorSuffix = empty($error) ? '' : 'Error';
            unset($options['error']);
        }
        $label = $options['label'];
        unset($options['label']);
        $nestedInput = false;
        if ($options['type'] === 'checkbox') {
            $nestedInput = true;
        }
        $nestedInput = isset($options['nestedInput']) ? $options['nestedInput'] : $nestedInput;
        if ($nestedInput === true && $options['type'] === 'checkbox' && !array_key_exists('hiddenField', $options) && $label !== false) {
            $options['hiddenField'] = '_split';
        }
        $input = $this->_getInput($fieldName, $options);
        if ($options['type'] === 'hidden' || $options['type'] === 'submit') {
            if ($newTemplates) {
                $templater->pop();
            }
            return $input;
        }
        $label = $this->_getLabel($fieldName, compact('input', 'label', 'error', 'nestedInput') + $options);
        $result = $this->_groupTemplate(compact('input', 'label', 'error', 'options'));
        $result = $this->_inputContainerTemplate(['content' => $result, 'error' => $error, 'errorSuffix' => $errorSuffix, 'options' => $options]);
        if ($newTemplates) {
            $templater->pop();
        }
        return $result;
    }

Usage Example

 public function input($fieldName, array $options = [])
 {
     $options += ['type' => null, 'label' => null, 'error' => null, 'required' => null, 'options' => null, 'templates' => []];
     $options = $this->_parseOptions($fieldName, $options);
     $options += ['id' => $this->_domId($fieldName)];
     $finalClasses = 'form-control';
     switch ($options['type']) {
         case 'checkbox':
             $finalClasses = '';
             $options['templates']['checkboxWrapper'] = '<div class="checkbox"><label>{{input}}{{label}}</label></div>';
             $options['templates']['label'] = '{{text}}';
             break;
         case 'radio':
             $options['templates']['radioWrapper'] = '<div class="radio"><label>{{input}}{{label}}</label></div>';
             $options['templates']['label'] = '{{text}}';
             break;
         case 'file':
             $options['templates']['inputContainer'] = '<div class="form-group {{type}}{{required}}">{{content}}</div>';
             $options['templates']['label'] = isset($options['templates']['label']) ? $options['templates']['label'] : '<label>{{input}}{{text}}</label>';
             break;
         case 'password':
             $options['templates']['inputContainer'] = '<div class="form-group {{type}}{{required}}">{{content}}</div>';
             $options['templates']['label'] = isset($options['templates']['label']) ? $options['templates']['label'] : '<label>{{input}}{{text}}</label>';
             break;
         default:
     }
     return parent::input($fieldName, $this->_injectStyles($options, $finalClasses));
 }
All Usage Examples Of Cake\View\Helper\FormHelper::input