/** * Updates an existing Task model. * If update is successful, the browser will be redirected to the 'update' page. * @param integer $id * @return mixed */ public function actionUpdate($id = null, $partner_id = null) { if ($id) { $model = $this->findModel($id); } else { $model = new Task(); } if ($model->load(Yii::$app->request->post()) && $model->save()) { Yii::$app->session->setFlash('success', __('Your changes have been saved successfully.')); return $this->redirect(['index']); } else { if (!$id) { $model->timestamp = Yii::$app->formatter->asDate(time()); $model->user_id = Yii::$app->user->id; if ($partner_id) { $model->select_partner = Partner::findOne($partner_id); } } return $this->renderAjax('update', ['model' => $model]); } }
/** * Finds the Partner model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Partner the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Partner::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }