S
S
Sergey Semenko2015-03-13 16:09:28
Yii
Sergey Semenko, 2015-03-13 16:09:28

Yii2 - why aren't default values ​​set for dropDownList?

Here is a part of the form

<?= $form->field($model, 'categories[]')->dropDownList(Category::getCategoryList(), [
            'multiple' => true,
            'options' => $movie->getCategorySelected(),
        ]
    ) ?>

This is what is returned by $movie->getCategorySelected()
array(2) { [5]=> array(1) { ["selected"]=> bool(true) } [27]=> array(1) { ["selected"]=> bool(true) } }

It should work, but it doesn't, how can I fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Bay, 2015-03-13
@kawabanga

well also look that is deduced and that is expected. array('options'=> , 'prompt' => )
is expected and you load array(5=>, 27=>) there I think you need to use the following code www.yiiframework.com/doc-2.0/yii -helpers-basehtml.... ()-detail

'options'=> [ 'options'=>$movie->getCategorySelected()
]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question