PHP code example of 2amigos / yii2-select2-widget

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

    

2amigos / yii2-select2-widget example snippets

 
use dosamigos\select2\Select2:


// with \yii\bootstrap\ActiveForm;
echo $form
    ->field($model, 'attribute')
    ->widget(
        Select2::class, 
        [
            'items' => $data, // $data should be the same as the items provided to a regular yii2 dropdownlist
            'clientOptions' => ['theme' => 'classic']
        ]
    );
    
// as widget 
echo Select2::widget([
    'name' => 'my-name',
    'value' => 'my-value',
    'clientOptions' => [
        'maximumInputLength' => 20
    ]
]); 
 
use dosamigos\select2\Select2Bootstrap:

// displaying the select2 with prepended addon
echo $form
    ->field($model, 'attribute')
    ->widget(
        Select2Bootstrap::class, 
        [
            'items' => $data, // $data should be the same as the items provided to a regular yii2 dropdownlist
            'template' => '<div class="input-group">' .
                  '<span class="input-group-btn">' .
                  '<button class="btn btn-default" type="button" data-select2-open="multi-prepend-append">' .
                  'State' .
                  '</button>' .
                  '</span>' .
                  '{input}' .
                   '<span class="input-group-addon">Append</span>' .
                   '</div>'
        ]
    );
    
// as widget 
echo Select2Bootstrap::widget([
    'name' => 'my-name',
    'value' => 'my-value',
    'clientOptions' => [
        'maximumInputLength' => 20
    ]
]); 
bash 
./vendor/bin/php-cs-fixer fix ./src --config .php_cs