I have a Select2 widget with items getted from a PostgreSQL query:

View file:

<?= $form->field($model, 'id_person')->widget(Select2::classname(), [
    'items' => Persons::findPersons(),
]) ?>

Model file:

public static function findPersons() {
    $persons = self::find()
        ->select([
            'id_person',
            new Expression("
                CASE WHEN working THEN '(Yes)'
                     ELSE '(No)'
                END
                || ' '
                || name AS name
            "),
        ])
        ->all();

    return ArrayHelper::map($persons, 'id_person', 'name');
}

I need to give format to the Select2 so I tried to modify the CASE but it doesn't work:

CASE WHEN working THEN '<b>(Yes)</b>'
     ELSE '<b>(No)</b>'
END

0 Answers