PHP code example of silentlun / yii2-widget-select2

1. Go to this page and download the library: Download silentlun/yii2-widget-select2 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/ */

    

silentlun / yii2-widget-select2 example snippets

 
use silentlun\select2\Select2:


// with \yii\bootstrap\ActiveForm;
echo $form
    ->field($model, 'attribute')
    ->widget(
        Select2::class, 
        [
            'items' => $data, // $data 应该与提供给常规 Yi2 DropdownList 的项目相同
            'options' => ['placeholder' => '选择', 'multiple' => true],
            'clientOptions' => ['theme' => 'classic']
        ]
    );
    
// as widget 
echo Select2::widget([
    'name' => 'my-name',
    'value' => 'my-value',
    'clientOptions' => [
        'maximumInputLength' => 20
    ]
]); 

php composer.phar