Пример #1
0
 /**
  * Render the switch button checkbox.
  * @return string
  * @uses [yii\helper\BaseHtml::checkbox()](http://www.yiiframework.com/doc-2.0/yii-helpers-basehtml.html#checkbox()-detail)
  */
 protected function renderSwitch()
 {
     $value = ArrayHelper::getValue($this->inputOptions, 'value', null);
     if ($this->hasModel()) {
         $attributeValue = Html::getAttributeValue($this->model, $this->attribute);
         $this->checked = "{$value}" === "{$attributeValue}";
     }
     $name = ArrayHelper::remove($this->inputOptions, 'name', null);
     return implode("\n", [Html::beginTag('label'), $this->renderLabel('off'), Html::checkbox($name, $this->checked, $this->inputOptions), Html::tag('span', '', ['class' => 'lever']), $this->renderLabel('on'), Html::endTag('label')]);
 }