/** * Updates an existing Project model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $role = new ProjectRole(); $roles = ProjectRole::find()->where(['project_id' => $id])->all(); // Check if new role added and save if ($role->load(Yii::$app->request->post())) { $role->project_id = $id; if ($role->save()) { Yii::$app->session->setFlash('success', 'Role successfully added'); } return $this->redirect(['update', 'id' => $model->id]); } if ($model->load(Yii::$app->request->post()) && $model->save()) { Yii::$app->session->setFlash('success', 'Project successfully updated'); return $this->redirect(['update', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'role' => $role, 'roles' => $roles]); } }