|
- <?php
-
-
- namespace yii\widgets;
-
- use Yii;
- use yii\base\Widget;
- use yii\base\Model;
- use yii\base\InvalidConfigException;
- use yii\helpers\Html;
-
-
- class InputWidget extends Widget
- {
-
-
- 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;
- }
- }
|