dropdown list in yii 2


now i am start learning yii 2.0…

i have create an application…

now i want dropdown for country table…

please i want the syntax for that…


Some examples:


i got the solution…its quite easy…

two steps :

  1. add :

  use yii\helpers\ArrayHelper;

              use app\models\Country;

    <?= Html::activeDropDownList($model, 'country_id',

      ArrayHelper::map(Country::find()->all(), 'id', 'name'), ['prompt'=>'-Choose a Country-']) ?>

Here,ArrayHelper in Yii2 replaces the CHtml list data in Yii 1.1.

so, add this in your _form.php

Hi yiim,

Thanks a lot for your reply…

Thank you.