我使用带有多个选项的Kartik select dropDownList。
http://demos.krajee.com/widget-details/select2 我可以在循环中添加一些项目,但我无法更新项目,因为我得到了
https://gyazo.com/fae968ed6f881307652598cf2287a32c
有什么不对?
我在环路中创建新项目的控制器操作
public function actionCreate()
{
$model = new reservation();
if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($model);
}
if ($model->load(Yii::$app->request->post())) {
foreach ($_POST['Reservation']['id_place'] as $key=> $item) {
$model->id_reservation = NULL;
$model->create_at = date('Y-m-d H:i:s');
$model->auth_key = Yii::$app->security->generateRandomString();
$model->id_place=$item;
$model->isNewRecord = true;
$model->save();
}
return $this->redirect(['view', 'id' => $model->id_reservation]);
} else {
$model->auth_key = Yii::$app->security->generateRandomString();
return $this->renderAjax('create', [
'model' => $model,
]);
}
}
我的更新操作
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id_reservation]);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
我的观点
echo $form->field($model, 'id_place')->widget(Select2::classname(), [
'theme' => Select2::THEME_KRAJEE,
'language' => 'pl',
'options' => ['placeholder' => 'Select place',
'id' => 'rezerwacja',
'multiple'=>true,
],
'pluginOptions' => [
'allowClear' => true,
],
])->label("Miejsce: max (5)"); ?>