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

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

This method converts the result BaseHtml::getInputName into a valid input ID. For example, if BaseHtml::getInputName returns Post[content], this method will return post-content.
public static getInputId ( Model $model, string $attribute ) : string
$model yii\base\Model the model object
$attribute string the attribute name or expression. See [[getAttributeName()]] for explanation of attribute expression.
Результат string the generated input ID
    public static function getInputId($model, $attribute)
    {
        $name = strtolower(static::getInputName($model, $attribute));
        return str_replace(['[]', '][', '[', ']', ' ', '.'], ['', '-', '-', '', '-', '-'], $name);
    }

Usage Example

 public function run()
 {
     $this->view->registerAssetBundle(MultiSelectAsset::className());
     $options = $this->options;
     if (isset($options['id'])) {
         $id = $options['id'];
     } else {
         $id = BaseHtml::getInputId($this->model, $this->attribute);
     }
     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;
     //        }
     $len = strlen($this->attribute);
     $widget = Html::beginTag('div', ['id' => $id, 'name' => $name]);
     foreach ($this->model as $k => $v) {
         if (substr($k, 0, $len + 1) == $this->attribute . '_') {
             $widget .= Html::activeCheckbox($this->model, $k, ['labelOptions' => ['class' => 'checkbox-inline']]);
         }
     }
     $widget .= Html::endTag('div');
     echo $widget;
 }
All Usage Examples Of yii\helpers\BaseHtml::getInputId