/**
  * Updates an existing Monitoring1 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);
     $months = Month::find()->all();
     $years = Year::find()->all();
     $model->user_id = Yii::$app->user->id;
     //      добавление даты  http://www.yiiframework.com/doc-2.0/guide-output-formatting.html
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model, 'months' => $months, 'years' => $years]);
     }
 }
예제 #2
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $r = Month::find($id);
     return response()->json($r);
 }
 public function actionGetMonthByYear()
 {
     $id = Yii::$app->request->post('id');
     $monthsExist = Monitoring2::find()->select('month_id')->where(['year_id' => $id])->andWhere(['user_id' => Yii::$app->user->id])->column();
     $months = Month::find()->where(['NOT IN', 'id', $monthsExist])->all();
     $arrayMonth = ArrayHelper::map($months, 'id', 'month');
     $options = '<option value="">Оберіть місяць</option>';
     foreach ($arrayMonth as $key => $value) {
         $options .= '<option value=' . $key . '>' . $value . '</option>';
     }
     return $options;
 }