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

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

This method generates a name that can be used as the input name to collect user input for the specified attribute. The name is generated according to the [[Model::formName|form name]] of the model and the given attribute name. For example, if the form name of the Post model is Post, then the input name generated for the content attribute would be Post[content]. See BaseHtml::getAttributeName for explanation of attribute expression.
public static getInputName ( Model $model, string $attribute ) : string
$model yii\base\Model the model object
$attribute string the attribute name or expression
Результат string the generated input name
    public static function getInputName($model, $attribute)
    {
        $formName = $model->formName();
        if (!preg_match('/(^|.*\\])([\\w\\.]+)(\\[.*|$)/', $attribute, $matches)) {
            throw new InvalidParamException('Attribute name must contain word characters only.');
        }
        $prefix = $matches[1];
        $attribute = $matches[2];
        $suffix = $matches[3];
        if ($formName === '' && $prefix === '') {
            return $attribute . $suffix;
        } elseif ($formName !== '') {
            return $formName . $prefix . "[{$attribute}]" . $suffix;
        } else {
            throw new InvalidParamException(get_class($model) . '::formName() cannot be empty for tabular inputs.');
        }
    }

Usage Example

Пример #1
0
 public function run()
 {
     $options = $this->options;
     if (isset($options['id'])) {
         $id = $options['id'];
     } else {
         $id = 'editor';
     }
     if (isset($options['name'])) {
         $name = $options['name'];
     } elseif ($this->hasModel()) {
         $name = BaseHtml::getInputName($this->model, $this->attribute);
     } else {
         $name = $this->name;
     }
     if (isset($options['value'])) {
         $value = $options['value'];
     } elseif ($this->hasModel()) {
         $value = BaseHtml::getAttributeValue($this->model, $this->attribute);
     } else {
         $value = $this->value;
     }
     echo Html::beginTag('script', ['id' => $id, 'type' => 'text/plain', 'name' => $name, 'style' => "height:{$this->height}"]);
     echo $value;
     echo Html::endTag('script');
     if (!isset($options['config'])) {
         $options['config'] = [];
     }
     $ueditorConfig = ArrayHelper::merge(['serverUrl' => Url::to(['ueditor/controller'])], $options['config']);
     $config = Json::encode($ueditorConfig);
     $view = $this->getView();
     UEditorAsset::register($view);
     $view->registerJs("var ue = UE.getEditor('{$id}', {$config});");
 }
All Usage Examples Of yii\helpers\BaseHtml::getInputName