Slider.php 1.28 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
<?php
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

namespace yii\jui;

use Yii;
use yii\helpers\Html;

/**
 * Slider renders a slider jQuery UI widget.
 *
 * For example:
 *
 * ```php
Alexander Makarov committed
19
 * echo Slider::widget([
20 21
 *     'model' => $model,
 *     'attribute' => 'amount',
Alexander Makarov committed
22
 *     'clientOptions' => [
23 24
 *         'min' => 1,
 *         'max' => 10,
Alexander Makarov committed
25 26
 *     ],
 * ]);
27 28 29 30 31
 * ```
 *
 * The following example will use the name property instead:
 *
 * ```php
Alexander Makarov committed
32
 * echo Slider::widget([
33
 *     'name'  => 'amount',
Alexander Makarov committed
34
 *     'clientOptions' => [
35 36
 *         'min' => 1,
 *         'max' => 10,
Alexander Makarov committed
37 38
 *     ],
 * ]);
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
 *```
 *
 * @see http://api.jqueryui.com/slider/
 * @author Alexander Makarov <sam@rmcreative.ru>
 * @since 2.0
 */
class Slider extends InputWidget
{
	/**
	 * Renders the widget.
	 */
	public function run()
	{
		echo $this->renderWidget();
		$this->registerWidget('slider', SliderAsset::className());
	}

	/**
	 * Renders the Slider widget.
	 * @return string the rendering result.
	 */
	public function renderWidget()
	{
		if ($this->hasModel()) {
			return Html::activeTextInput($this->model, $this->attribute, $this->options);
		} else {
			return Html::textInput($this->name, $this->value, $this->options);
		}
	}
}