Yii2 + Seletc 2 + Tags

view

echo '<label class="control-label">Tag Content</label>'; echo Select2::widget([ 'model' => $model, 'attribute' => 'tags', 'name' => 'tags', 'data' => common\models\Tag::getOptions(), 'options' => [ 'placeholder' => 'Select a color ...', 'class' => 'form-control', 'multiple' => true ], ]);

Model

class Model { public static function getOptions(){ $data= static::find()->all(); $value=(count($data)==0)? [''=>'']: \yii\helpers\ArrayHelper::map($data, 'id','name'); //id = your ID model, name = your caption return $value; } }