/** * Action of create or update item. **/ public function actionSaveItem() { $item = null; if (isset($_POST['ItemForm']['oldName'])) { $item = $this->findItem($_POST['ItemForm']['oldName']); } $model = new ItemForm($item); if ($model->load(Yii::$app->request->post()) && $model->save()) { return Json::encode($model); } throw new HttpException(406, Json::encode($model->getErrors())); }
/** * Action of create or update a item(role or permission). **/ public function actionSave() { $item = null; if (isset($_POST['ItemForm']['oldName'])) { $item = $this->findItem($_POST['ItemForm']['oldName']); } $model = new ItemForm($item); if (!$model->load(Yii::$app->request->post())) { Yii::$app->response->setStatusCode(406); return ['errors' => ['Wrong Post datum']]; } if (!$model->load(Yii::$app->request->post()) || !$model->save()) { Yii::$app->response->setStatusCode(406); return ['errors' => $model->getErrors()]; } return $model; }