Example #1
0
 /**
  * Updates an existing Timesheet 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);
     $query = Work::find()->where(['timesheet_id' => $model->id]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => false]);
     if (Yii::$app->request->post()) {
         $works = Yii::$app->request->post('Work');
         foreach ($works as $work) {
             $new_work = Work::findOne($work['id']);
             $new_work->attributes = $work;
             $new_work->updated_at = time();
             if ($new_work->update() === false) {
                 return $this->render('update', ['model' => $model, 'dataProvider' => $dataProvider]);
             }
         }
         Yii::$app->session->setFlash('updateOK');
         return $this->redirect('index.php?r=timesheet/view&id=' . $model->id);
     }
     return $this->render('update', ['model' => $model, 'dataProvider' => $dataProvider]);
 }
Example #2
0
 /**
  * Finds the Work model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  *
  * @param integer $id
  *
  * @return Work the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findWorkModel($id)
 {
     if (($model = Work::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('Запрошенная страница не найдена');
     }
 }
Example #3
0
 /**
  * Finds the Work model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Work the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Work::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }