如何使用
activeform
和模型在yii2
中制作一个dropdown
?由于所有方法在yii2
中都已更改,因此请告知新的方法。activeform
和模型在yii2
中制作一个dropdown
?由于所有方法在yii2
中都已更改,因此请告知新的方法。<?=$form->field($model, 'category_id')->dropdownList(
\common\models\Category::find()
->select(['name', 'id'])
->indexBy('id')
->column(),
['prompt'=>'select category']
)?>
Html::activeDropDownList($model, 'id', ArrayHelper::map(AttendanceLabel::find()->all(), 'id', 'label_name'), ['prompt' => '考勤状态']);
还可以这样做。如果您想要添加前缀或后缀图标,这将非常有帮助。
<?php $form = ActiveForm::begin();
echo $form->field($model, 'field')->begin();
echo Html::activeLabel($model, 'field', ["class"=>"control-label col-md-4"]); ?>
<div class="col-md-5">
<?php echo Html::activeDropDownList($model, 'field', $array_list, ['class'=>'form-control']); ?>
<p><i><small>Please select field</small></i>.</p>
<?php echo Html::error($model, 'field', ['class'=>'help-block']); ?>
</div>
<?php echo $form->field($model, 'field')->end();
ActiveForm::end();?>