PHP code example of diiimonn / yii2-widget-checkbox-multiple
1. Go to this page and download the library: Download diiimonn/yii2-widget-checkbox-multiple library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
diiimonn / yii2-widget-checkbox-multiple example snippets
...
use diiimonn\widgets\CheckboxMultiple;
use yii\helpers\Url;
...
<?= $form->field($model, 'books')->widget(CheckboxMultiple::className(), [
'dataAttribute' => 'name',
'scriptOptions' => [
'ajax' => [
'url' => Url::toRoute(['books']),
],
],
'placeholder' => Yii::t('app', 'Select ...'),
])
...
use diiimonn\widgets\CheckboxMultiple;
use yii\helpers\Url;
...
<?= CheckboxMultiple::widget([
'model' => $model,
'attribute' => 'books',
'dataAttribute' => 'name',
'scriptOptions' => [
'ajax' => [
'url' => Url::toRoute(['books']),
],
],
'placeholder' => Yii::t('app', 'Select ...'),
])
...
'scriptOptions' => [
'defaultCheckbox' => false,
'limit' => 10,
'templateItem' => Html::tag('li', Html::tag('span', '{text}') .
Html::tag('span', Html::tag('span', '', [
'class' => 'glyphicon glyphicon-remove',
]), [
'class' => 'checkbox-multiple-remove-item',
]), [
'class' => 'checkbox-multiple-item',
]),
'templateInput' => Html::textInput('checkbox-multiple-input', '', [
'class' => 'form-control input-sm',
]),
'slimScroll' => [
'color' => '#333',
'railOpacity' => 0.5,
'railColor' => '#666666',
],
],
...
use yii\db\Query;
...
public function actionBooks()
{
Yii::$app->response->format = 'json';
$json = new \stdClass();
$query = new Query();
$query->select([
'id' => 'id',
'text' => 'name'
]);
$query->from(BookModel::tableName());
if ($search = Yii::$app->request->post('search', '')) {
$query->where(['like', 'username', $search]);
}
$query->orderBy([
'name' => SORT_ASC
]);
if ($itemsId = Yii::$app->request->post('itemsId', [])) {
$query->andWhere(['not in', 'id', $itemsId]);
}
$query->limit(20);
$command = $query->createCommand();
$data = $command->queryAll();
$json->results = array_values($data);
return $json;
}
$ php composer.phar