yii\helpers\BaseHtml::activeCheckboxList PHP Метод

activeCheckboxList() публичный статический Метод

A checkbox list allows multiple selection, like BaseHtml::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 static activeCheckboxList ( Model $model, string $attribute, array $items, array $options = [] ) : string
$model yii\base\Model the model object
$attribute string the attribute name or expression. See [[getAttributeName()]] for the format about attribute expression.
$items array the data item used to generate the checkboxes. The array keys are the checkbox values, and the array values are the corresponding labels. Note that the labels will NOT be HTML-encoded, while the values will.
$options array options (name => config) for the checkbox list container tag. The following options are specially handled: - tag: string|false, the tag name of the container element. False to render checkbox without container. See also [[tag()]]. - unselect: string, the value that should be submitted when none of the checkboxes is selected. You may set this option to be null to prevent default value submission. If this option is not set, an empty string will be submitted. - encode: boolean, whether to HTML-encode the checkbox labels. Defaults to true. This option is ignored if `item` option is set. - separator: string, the HTML code that separates items. - itemOptions: array, the options for generating the checkbox tag using [[checkbox()]]. - item: callable, a callback that can be used to customize the generation of the HTML code corresponding to a single item in $items. The signature of this callback must be: ```php function ($index, $label, $name, $checked, $value) ``` where $index is the zero-based index of the checkbox in the whole list; $label is the label for the checkbox; and $name, $value and $checked represent the name, value and the checked status of the checkbox input. See [[renderTagAttributes()]] for details on how attributes are being rendered.
Результат string the generated checkbox list
    public static function activeCheckboxList($model, $attribute, $items, $options = [])
    {
        return static::activeListInput('checkboxList', $model, $attribute, $items, $options);
    }

Usage Example

Пример #1
0
                </div>

            </div>

            <div class="col-lg-7">

                <div class="row">

                    <?php 
echo BaseHtml::activeCheckboxList($model, 'participantsId', ArrayHelper::map($participants, function ($item) {
    /** @var $item \common\models\vks\Participant */
    return (string) $item->primaryKey;
}, 'name'), ['item' => function ($index, $label, $name, $checked, $value) use($participants) {
    /** @var Participant $participant */
    $participant = $participants[$index];
    $defaultOptions = ['value' => $value, 'data' => ['company-id' => (string) $participant->companyId]];
    $label .= $participant->ahuConfirmation ? '&nbsp;<span class="glyphicon glyphicon-star text-warning"></span>' : '';
    $options = array_merge_recursive($defaultOptions, $participant->isBusy ? ['label' => $label . '<p><small>занято с ' . MinuteFormatter::asString($participant->busyFrom) . ' до ' . MinuteFormatter::asString($participant->busyTo) . '</small></p>', 'labelOptions' => ['class' => 'disabled'], 'disabled' => true] : ['label' => $label, 'data' => ['name' => $participant->name, 'short-name' => $participant->shortName, 'company-name' => $participant->company->name, 'contact' => $participant->contact, 'ip-address' => $participant->ipAddress]]);
    $tooltip = $participant->ahuConfirmation ? ['data' => ['toggle' => 'tooltip', 'html' => true, 'placement' => 'top', 'container' => '#vks-participants', 'title' => Html::tag('div', 'Бронь необходимо согласовать с') . Html::tag('div', $participant->confirmPerson->fullName) . Html::tag('div', $participant->confirmPerson->post) . Html::tag('div', 'тел: ' . $participant->confirmPerson->phone . ', ' . $participant->confirmPerson->email)]] : [];
    return Html::beginTag('div', array_merge(['class' => 'col-lg-4 vks-room', 'style' => 'display:none'], $tooltip)) . Html::checkbox($name, $checked, $options) . Html::endTag('div');
}]);
?>

                </div>

            </div>

        </div>

    </div>