最新消息: 新版网站上线了!!!

yii2下拉菜单dropDownList的例子

Yii2.0 默认的 dropdownlist 的使用方法.
<?php echo $form->field($model, 'name[]')->dropDownList(['a' => 'Item A', 'b' => 'Item B', 'c' => 'Item C']); ?>yii2中加放请选择的下拉菜单
 
<php echo $form->field($model, 'name[]')->dropDownList($listData, 
                        ['prompt'=>'Select...']);>
 
DropDownList 在模型中使用
 
<?php 
//use app\models\Country;
$countries=Country::find()->all();
 
//use yii\helpers\ArrayHelper;
$listData=ArrayHelper::map($countries,'code','name');
 
echo $form->field($model, 'name')->dropDownList(
                                $listData, 
                                ['prompt'=>'Select...']);
?>

转载请注明:谷谷点程序 » yii2下拉菜单dropDownList的例子