-
Notifications
You must be signed in to change notification settings - Fork 0
/
CheckBoxList.php
49 lines (39 loc) · 1.03 KB
/
CheckBoxList.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/**
* @copyright (C) FIT-Media.com {@link http://fit-media.com}
* Date: 09.09.15, Time: 23:52
*
* @author Dmitrij "m00nk" Sheremetjev <[email protected]>
* @package
*/
namespace m00nk\b3w;
use yii\helpers\Html;
use yii\base\Widget;
use yii\widgets\InputWidget;
/**
* Class CheckBoxList
* @package m00nk\b3w
*/
class CheckBoxList extends InputWidget
{
/** @var array ассоциативный массив значений */
public $items = [];
/** @var string Имя для чекбоксов (типа 'Categories[]') */
public $name = '';
public function run()
{
$list = [];
$selectedValue = $this->model->{$this->attribute};
$_index = 0;
foreach ($this->items as $k => $v)
{
$list[] = Html::tag('li',
Html::checkbox($this->name, $k == $selectedValue, ['id' => $this->id.'_'.$_index, 'hidden' => 'hidden']).
Html::label($v, $this->id.'_'.$_index)
);
$_index++;
}
$this->options['class'] .= ' m00nk_b3w_checkboxlist';
echo Html::tag('ul', implode('', $list), $this->options);
}
}