Yii has a very good set of form widgets, but as with every framework out there, Yii does not have them all. In this recipe, we will learn how to create your own input widget. For our example, we will create a range input widget.
Create a new application by using the Composer package manager, as described in the official guide at http://www.yiiframework.com/doc-2.0/guide-start-installation.html.
Create a widget file,
@app/components/RangeInputWidget.php
, as follows:<?php namespace app\components; use yii\base\Exception; use yii\base\Model; use yii\base\Widget; use yii\helpers\Html; class RangeInputWidget extends Widget { public $model; public $attributeFrom; public $attributeTo; public $htmlOptions = []; protected function hasModel() { return $this->model instanceof Model&& $this->attributeFrom !== null&& $this->attributeTo !== null;} public function run() { ...