public function actionUpdate($id) { $model = $this->findModel($id); $last_executor_id = $model->executor_id; $modelHistory = new TaskHistory(); if ($model->load(Yii::$app->request->post(), '') && $model->save()) { if ($last_executor_id != $model->executor_id && $modelHistory->load(Yii::$app->request->post(), '')) { $modelHistory->task_id = $model->id; $modelHistory->last_executor_id = $last_executor_id; $modelHistory->new_executor_id = $model->executor_id; $modelHistory->save(); } return $model; } throw new ServerErrorHttpException('Failed to update the object for unknown reason.'); }