A
A
akula222016-12-27 15:27:15
Yii
akula22, 2016-12-27 15:27:15

What to do if dropDownList = null?

<?= $form->field($model, 'teams')->dropDownList($teams, [
                    'multiple' => 'true',
                ]); ?>

But if the teams is empty, the error Invalid argument supplied for foreach () falls out.
How can I display an empty multi select, then I add elements to it in js

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Bukharev, 2016-12-27
@akula22

<?= $form->field($model, 'teams')->dropDownList(!empty($teams) ? $teams : [], [
                    'multiple' => 'true',
                ]); ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question