public function actionUpdate() { $post = yii::$app->request->post('FilterValue'); $model = FilterValue::findOne(['item_id' => $post['item_id'], 'filter_id' => $post['filter_id']]); if (!$model) { $model = new FilterValue(); } else { $filter = Filter::findOne($model->filter_id); if ($filter->type == 'radio') { FilterValue::deleteAll(['item_id' => $post['item_id'], 'filter_id' => $post['filter_id']]); $model = new FilterValue(); } } $json = []; if ($model->load(yii::$app->request->post()) && $model->save()) { $json['result'] = 'success'; } else { $json['result'] = 'fail'; } return json_encode($json); }