kartik select 2 yii2

To use the Kartik Select2 extension in Yii2, you can follow these steps:

  1. Install the Kartik Select2 extension by adding it to your project's composer.json file and running the composer update command. Here's an example of how to add it to your composer.json file:

json "require": { "kartik-v/yii2-widget-select2": "@dev" }

  1. After installing the extension, you can use it in your Yii2 views or forms. Here's an example of how to use the Kartik Select2 widget in a view:

```php use kartik\select2\Select2; use yii\helpers\Html;

echo Select2::widget([ 'name' => 'state_200', 'data' => $us_states, 'size' => Select2::MEDIUM, 'addon' => [ 'prepend' => [ 'content' => '' ], 'append' => [ 'content' => Html::button('', [ 'class' => 'btn btn-primary', 'title' => 'Mark on map', 'data-toggle' => 'tooltip' ]), 'asButton' => true ] ] ]); ```

This example creates a Select2 widget with the name 'state_200', using the $us_states array as the data source. It also adds a globe icon as a prepend addon and a map marker button as an append addon.

Note: Make sure to replace $us_states with your own data source.

  1. Customize the Select2 widget according to your needs. You can refer to the Kartik Select2 documentation for more information on available options and configurations.

That's it! You have now successfully integrated the Kartik Select2 extension into your Yii2 project.