As in Yii 2 indicate the selected value in dropdown



  • I can't find the value of the selected list.

     <?= $form->field($model, 'attr_id')->dropDownList(ArrayHelper::map(Attr::find()->all(), 'id', 'name'),
        ['prompt'=>'Select...'] ) ?>
    


  • It's not possible to indicate in the control room.

    public function actionCreate()
    {
        $model = new Bonus();
        $model->attr_id = '2'; 
    
    if ($model-&gt;load(Yii::$app-&gt;request-&gt;post()) &amp;&amp; $model-&gt;save())
    {
        return $this-&gt;redirect(['view', 'id' =&gt; $model-&gt;id]);
    }
    else
    {
        return $this-&gt;render('create', [
                    'model' =&gt; $model,
        ]);
    }
    

    }


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2