Exemplo n.º 1
0
 /**
  * Creates a new Section model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Section();
     if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
         \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
         return ActiveForm::validate($model);
     }
     if ($model->load(Yii::$app->request->post())) {
         $model->attributes = $_POST['Section'];
         $model->created_at = new \yii\db\Expression('NOW()');
         $model->created_by = Yii::$app->getid->getId();
         $model->save();
         return $this->redirect(['index']);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Exemplo n.º 2
0
 /**
  * Creates a new Courses model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Courses();
     $batch = new Batches();
     $section = new Section();
     if ($model->load(Yii::$app->request->post()) && $batch->load(Yii::$app->request->post()) && $section->load(Yii::$app->request->post()) && Yii::$app->request->isAjax) {
         \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
         return array_merge(ActiveForm::validate($model), ActiveForm::validate($batch), ActiveForm::validate($section));
     }
     if ($model->load(Yii::$app->request->post()) && $batch->load(Yii::$app->request->post()) && $section->load(Yii::$app->request->post())) {
         $model->attributes = $_POST['Courses'];
         $model->created_by = Yii::$app->getid->getId();
         $model->created_at = new \yii\db\Expression('NOW()');
         if ($model->save()) {
             if (isset($_POST['Batches'])) {
                 $batch->attributes = $_POST['Batches'];
                 $batch->batch_course_id = $model->course_id;
                 $batch->start_date = date('Y-m-d', strtotime($_POST['Batches']['start_date']));
                 $batch->end_date = date('Y-m-d', strtotime($_POST['Batches']['end_date']));
                 $batch->created_by = Yii::$app->getid->getId();
                 $batch->created_at = new \yii\db\Expression('NOW()');
                 if ($batch->save()) {
                     $section->attributes = $_POST['Section'];
                     $section->section_batch_id = $batch->batch_id;
                     $section->created_by = Yii::$app->getid->getId();
                     $section->created_at = new \yii\db\Expression('NOW()');
                     if ($section->save()) {
                         return $this->redirect(['index']);
                     } else {
                         return $this->render('create', ['model' => $model, 'batch' => $batch, 'section' => $section]);
                     }
                 }
             }
         } else {
             return $this->render('create', ['model' => $model, 'batch' => $batch, 'section' => $section]);
         }
     } else {
         return $this->render('create', ['model' => $model, 'batch' => $batch, 'section' => $section]);
     }
 }