123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- <?php
- namespace yii\widgets;
- use Yii;
- use yii\base\InvalidConfigException;
- use yii\base\Model;
- use yii\base\Widget;
- use yii\helpers\Html;
- class InputWidget extends Widget
- {
-
- public $field;
-
- public $model;
-
- public $attribute;
-
- public $name;
-
- public $value;
-
- public $options = [];
-
- public function init()
- {
- if ($this->name === null && !$this->hasModel()) {
- throw new InvalidConfigException("Either 'name', or 'model' and 'attribute' properties must be specified.");
- }
- if (!isset($this->options['id'])) {
- $this->options['id'] = $this->hasModel() ? Html::getInputId($this->model, $this->attribute) : $this->getId();
- }
- parent::init();
- }
-
- protected function hasModel()
- {
- return $this->model instanceof Model && $this->attribute !== null;
- }
-
- protected function renderInputHtml($type)
- {
- if ($this->hasModel()) {
- return Html::activeInput($type, $this->model, $this->attribute, $this->options);
- }
- return Html::input($type, $this->name, $this->value, $this->options);
- }
- }
|