/** * Lists all Log models. * @return mixed * @throws UserException */ public function actionIndex() { $goalId = (int) Yii::$app->request->get('goal_id', 0); if (!$goalId) { throw new UserException('Goal id is not provided'); } $goal = Goal::findOne($goalId); if (!$goal) { throw new UserException("Goal [{$goalId}] not found"); } $searchModel = new LogSearch(['goal_id' => $goalId]); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', ['goal' => $goal, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider]); }
/** * Creates a new Task model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed * @throws UserException */ public function actionCreate() { $goalId = (int) Yii::$app->request->get('goal_id', 0); if (!$goalId) { throw new UserException('Goal id is not provided'); } $goal = Goal::findOne($goalId); if (!$goal) { throw new UserException("Goal [{$goalId}] not found"); } $model = new Task(['goal_id' => $goalId]); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(Yii::$app->request->post('referrer') ?: $model->goal->urlTaskList()); } else { return $this->render('create', ['model' => $model]); } }
public function actionDeletegoal($goal_id, $kpa_id) { $goal = Goal::findOne($goal_id); //@todo: make sure to check for a valid object/model if (isset($goal)) { $goal->delete($goal_id); } Yii::$app->response->redirect(array('/site/viewkpa', 'id' => $kpa_id)); }
/** * Finds the Goal model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $alias * @return Goal the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($alias) { if (($model = Goal::findOne(['alias' => $alias])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }