它不会在我的多选下拉列表中显示默认选择值,我没有收到错误。是下拉列表接受数组的defalt select数组列表
public function actionCreate()
{
.......
$cust= implode('_',$_POST['supplier'] ['manufacture']);
$model->customer = $cust;
$model->save();
........
}
public function actionUpdate($id)
{
$model = $this->findModel($id);
$model->customer = explode('_',$model->customer);
if ($model->load(Yii::$app->request->post())) {
$cust= implode(',',$_POST['supplier']['manufacturer']);
$model->customer = $cust`enter code here`;
$model->save();
return $this->redirect(['view', 'id' => $model->ID]);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
<?=
$form->field($model, 'car_manufacturer[]')->dropDownList($model->getcustinfo(), [
'multiple'=>'multiple',
'class'=>'chosen-select input-md required',
]);
?>
答案 0 :(得分:1)
嗨传递选项中的selected value
['options' => $yourvalue => ['Selected'=>'selected']]
您应该在选项中传递array
['options' =>
[
$id1 => ['selected' => true]
],
[
$id2 => ['selected' => true]
],
]
您可以使用foreach
循环制作此array
答案 1 :(得分:0)
您应该只使用属性名称。
<?= $form->field($model, 'car_manufacturer')->dropDownList($model->getcustinfo(), [
'multiple'=>'multiple',
'class'=>'chosen-select input-md required', ])?>