public function actionAddgoal($kpa_id) { $model = new Goal(); $model->KPA_ID = $kpa_id; //$kpa = KPA::find() // ->where(['id'=>$kpa_id]); if ($model->load(Yii::$app->request->post()) && $model->validate()) { $model->User_ID = Yii::$app->user->identity->ID; if ($model->save()) { Yii::$app->session->setFlash('goalCreated', 'Goal has been saved'); } else { Yii::$app->session->setFlash('goalCreated', 'There was a problem saving this goal'); } return $this->render('addgoal', ['model' => $model, 'added' => true]); } return $this->render("addgoal", ['model' => $model, 'added' => false]); }