For an attribute expression like [0]dates[0], this method will return the value of $model->dates[0].
See BaseHtml::getAttributeName for more details about attribute expression.
If an attribute value is an instance of [[ActiveRecordInterface]] or an array of such instances,
the primary value(s) of the AR instance(s) will be returned instead.
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});"); }
public function validateAttribute($model, $attribute) { $value = (array) BaseHtml::getAttributeValue($model, $attribute); $count = count(array_filter($value)); if (isset($this->min) && $count < $this->min) { $this->addError($model, $attribute, $this->tooLess); } if (isset($this->max) && $count > $this->max) { $this->addError($model, $attribute, $this->tooMore); } }
protected function getInput($type, $list = false) { if ($this->hasModel()) { if (isset($this->options['maxlength']) && $this->options['maxlength'] === true) { unset($this->options['maxlength']); foreach ($this->model->getActiveValidators($this->attribute) as $validator) { if ($validator instanceof StringValidator && $validator->max !== null) { $this->options['maxlength'] = $validator->max; break; } } } if ($this->submit) { $this->name = isset($this->options['name']) ? $this->options['name'] : BaseHtml::getInputName($this->model, $this->attribute); } $this->value = isset($this->options['value']) ? $this->options['value'] : BaseHtml::getAttributeValue($this->model, $this->attribute); if (!array_key_exists('id', $this->options)) { $this->options['id'] = BaseHtml::getInputId($this->model, $this->attribute); } } return Html::textInput($this->name, $this->value, $this->options); }
public function thumbnail() { $this->parts['{thumbnail}'] = Html::beginTag('div', ['class' => 'img-thumbnail']); $max_width = 0; $max_height = 0; foreach ($this->thumbs as $name => $config) { if ($name === '') { $value_name = 'value'; $attribute_name = $this->attribute; } else { $value_name = 'value_' . $name; $attribute_name = $this->attribute . '_' . $name; } if (isset($options[$value_name])) { $value = $options[$value_name]; } elseif ($this->hasModel()) { $value = BaseHtml::getAttributeValue($this->model, $attribute_name); } else { $value = $this->__get($value_name); } if ($value) { $src = $this->url_prefix . $value; } else { $src = $this->default; } if ($config['height'] > $max_height) { $max_height = $config['height']; } if ($config['width'] > $max_width) { $max_width = $config['width']; } $this->parts['{thumbnail}'] .= Html::beginTag('div', ['class' => $this->id . '-img-preview', 'style' => 'height:' . $config['height'] . 'px; width:' . $config['width'] . 'px;']); $this->parts['{thumbnail}'] .= '<img src="' . $src . '" alt="" />'; $this->parts['{thumbnail}'] .= Html::endTag('div'); } $this->parts['{thumbnail}'] .= Html::endTag('div'); return $this; }