Yii2 CheckboxList in Search Model

I want to implement a checkBoxList in my Seachmodel but didn’t find a good solution. How can i do this? In My Model i have an Array for the Values:


const ART_BLACK = 10;

const ART_BLACK = 20;

const ART_BLACK = 30;

public function getColorText() {

        return [

            self::ART_BLACK => 'Black',

            self::ART_GREEN => 'Green',

            self::ART_ORANGE => 'Orange',



Seach Model:

How do i pass the Array to the Search Model? Also i want the selected values to be saved and displayed again?

Serach view (_search)

<?= $form->field($model, 'color[]')->checkboxList(??); ?>


$items = $this->getColorText(); 

$form->field($model, 'color')->checkboxList($items); 


Thanks for the Answer, but $this-> does in the view not refer to my Model. I can do this


$colors = new Colors;

$items = colors->getColorText();


$form->field($model, 'color')->checkboxList($items); 

This will display the checkBoxList. But after executing the search, all Elements are no longer selected. I can also put the array with the values in the SearchModel but still don’t know what’s best to save them to display again after the search.

Ok, i got my mistake

i made getColorText static and used this in the search view


<?= $form->field($model, 'art[]')->checkboxList(Color::getColorText()); ?>


<?= $form->field($model, 'art')->checkboxList(Color::getColorText()); ?>

Since $model is defined, $model->getColorText() should work also.