// 不操作数据库,直接填充数据显示
<? echo $form->field($model, 'edu')->dropDownList(['1'=>'大学','2'=>'高中','3'=>'初中'], ['prompt'=>'请选择','style'=>'width:120px']) ?>
// 下拉框读取数据库操作
<?= $form->field($user, 'communityid')->dropDownList(ArrayHelper::map(Community::find()->all(), 'id', 'name')) ?>
// 读取数据库,在前面加一个提示性的文字
<?= $form->field($exchange, 'target_communityid')->dropDownList(
Community::find()->select(['name', 'id'])->indexBy('id')->column(), ['prompt' => '请选择目标小区', 'value' => $user->communityid]
) ?>
或者用下面的方式
<?php
$arr = ArrayHelper::map(Community::find()->all(), 'id', 'name');
$arr = array_merge(['请选择小区'], $arr);
echo $form->field($user, 'communityid')->dropDownList($arr);
?>