Skip to content

How to make a drop down list in yii2

Last updated on February 10, 2018

In this post, I would like to show you how to create a drop-down list in yii2. This tutorial will help you to display the array data or model data in the drop-down list. I am using activeForm.

Drop down list syntax

echo $form->field($model, 'name_field')->dropDownList(
        [items],
        [options]
    );

Drop down list with Array

field($model, 'name')->dropDownList(['a' => 'Item A', 'b' => 'Item B', 'c' => 'Item C']); ?>

Drop down list with prompt

$listData = ['a' => 'Item A', 'b' => 'Item B', 'c' => 'Item C'];
field($model, 'name')->dropDownList($listData, ['prompt'=>'Select item']);>

Drop down list With table Model Data



all(), 'item_id', 'item_name')) ?>

0 0 votes
Article Rating
Subscribe
Notify of
guest

3 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments