yii2选择小部件 - 以相同的形式进行多重选择

时间:2016-08-19 14:39:45

标签: php yii2

我需要在同一表单中使用多个yii2 Select小部件。 对于每个学生,我需要显示选择小部件以选择课程。 当我在同一表格中使用多个选择小部件时,只会出现一个 怎么做?

$form->field($model, 'course')->widget(Select2::classname(), [
         'data' => ArrayHelper::map(course::find()->asArray()->where(['isActive' => '1'])->all(), 'id', 'name'),
         'options' => ['placeholder' => 'Select a course...'],
         'pluginOptions' => ['allowClear' => true],
              ]);

1 个答案:

答案 0 :(得分:0)

向{

这样的选项添加'multiple'=>true很简单

$form->field($model, 'course')->widget(Select2::classname(), [
         'data' => ArrayHelper::map(course::find()->asArray()->where(['isActive' => '1'])->all(), 'id', 'name'),
         'options' => ['placeholder' => 'Select a course...',,'multiple'=>TRUE],
         'pluginOptions' => ['allowClear' => true],
              ]);