dropdownList

I’m a newbie of YII2.

I found a difficulity as follows:

I use the code below:

echo $form->field($model, ‘pid’)->dropdownList(

Category::find()->select(['name', 'id'])->indexBy('id')->column(), ['prompt'=>'Select  CategoryName']

);

Result in html:

<label class="control-label" for="category-pid">Category-pid</label>

<select id="category-pid" class="form-contraol" name="Category[pid]">

<option value="">Select CategoryName</option>

How can I realize the html like below:

<label class="control-label" for="category-pid">Category-pid</label>

<select id="category-pid" class="form-control" name="Category[pid]">

<option value="0">Select CategoryName</option>

I want to give a default value zero to the first item, and I don’t want to add a record in the database to realize this.

Many Thanks!

hey,

do u want to select a default value in dropdownlist ? if so check the following link My link

Dear ajith,

Thanks.

I tried with your method, however, it doesn’t works.

Jack