yii\widgets\ActiveField::checkboxList PHP Method

checkboxList() public method

A checkbox list allows multiple selection, like ActiveField::listBox. As a result, the corresponding submitted value is an array. The selection of the checkbox list is taken from the value of the model attribute.
public checkboxList ( array $items, array $options = [] )
$items array the data item used to generate the checkboxes. The array values are the labels, while the array keys are the corresponding checkbox values.
$options array options (name => config) for the checkbox list. For the list of available options please refer to the `$options` parameter of [[\yii\helpers\Html::activeCheckboxList()]].
    public function checkboxList($items, $options = [])
    {
        $this->adjustLabelFor($options);
        $this->_skipLabelFor = true;
        $this->parts['{input}'] = Html::activeCheckboxList($this->model, $this->attribute, $items, $options);
        return $this;
    }

Usage Example

Beispiel #1
0
 public function checkboxList($items, $options = [])
 {
     $options['tag'] = 'ul';
     $inputId = Html::getInputId($this->model, $this->attribute);
     $this->selectors = ['input' => "#{$inputId} input"];
     $options['class'] = 'da-form-list inline';
     $encode = !isset($options['encode']) || $options['encode'];
     $itemOptions = isset($options['itemOptions']) ? $options['itemOptions'] : [];
     $options['item'] = function ($index, $label, $name, $checked, $value) use($encode, $itemOptions) {
         $checkbox = Html::checkbox($name, $checked, array_merge($itemOptions, ['value' => $value, 'label' => $encode ? Html::encode($label) : $label]));
         return '<li>' . $checkbox . '</li>';
     };
     return parent::checkboxList($items, $options);
 }
All Usage Examples Of yii\widgets\ActiveField::checkboxList