dropdown problem

I am trying to fill a drop-down menu with data from a query without success.

I use the code bellow,how can I fix it?

<?= $form->field($model, 'plan_id')->dropDownList([


 yii\helpers\ArrayHelper::map(Yii::$app->db->createCommand('SELECT id,name FROM plans')

            ->queryAll(), 'id', 'name'),


   ['prompt' => 'Set plan'],


I think that is a bad practice, because the view shouldn’t call model data. You should use a model to return an array and next use this date in the view:


    public function listaEstados($esta_id = null){

        $estados = ArrayHelper::map($this->find()->all(),'esta_id','esta_estado');


            return $estados;         


            return $estados[$esta_id];




            return $this->render('_form', [

                'model' => $model,

                'estados' => $estados->listaestados(),



<?= $form->field($model, 'tare_esta_id')->dropDownList($estados,array('prompt'=>Yii::t('app', 'Seleccione un estado'))) ?>    

First idea to try to debug your code is passing a mockup instead the query to check wich part has the problem. Try the following:

<?= $form->field($model, ‘plan_id’)->dropDownList(



        '1'=&gt;'A label',

        '2'=&gt;'Other label'

        '3'=&gt;'Another item label'),

[‘prompt’ => ‘Set plan’],

'options'=&gt; [ &#036;pl=&gt; ['Selected'=&gt;true] ]



If this works, then the problem is in the query.

The values of the array are converted to <option value="id">name</option>