コード例 #1
0
 /**
  * Creates a new Peoples model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Peoples();
     if ($model->load(Yii::$app->request->post())) {
         $birth = date('Y-m-d', strtotime($model->peopleBirthday));
         $fluDate = date('Y-m-d', strtotime($model->peopleFluDate));
         $model->peopleBirthday = $birth;
         $model->peopleFluDate = $fluDate;
         $currentYear = date('Y');
         $model->peopleFluTerm = $currentYear - date('Y', strtotime($model->peopleFluDate));
         //Вычисляю разницу текущего года и даты флюры
         $model->save();
         foreach ($model->graft as $m) {
             $gm = new graftsPeoples();
             $gm->peopleId = $model->peopleId;
             $gm->graftId = $m;
             $gm->insert();
         }
         foreach ($model->chronic as $c) {
             $cr = new chronicDiseasesPeoples();
             $cr->peopleId = $model->peopleId;
             $cr->chronicDiseasesId = $c;
             $cr->insert();
         }
         return $this->redirect(['view', 'id' => $model->peopleId]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }