예제 #1
0
 public function actionRacer()
 {
     $user = new User();
     $racer = new Racer();
     $races = Race::findAll(['status' => 'PENDING']);
     if ($user->load(Yii::$app->request->post()) && $racer->load(Yii::$app->request->post())) {
         $user->type = 'RACER';
         $user->status = 'ACTIVE';
         $user->password = hash('sha256', $user->identity);
         $user->creation_date = date('Y-m-d H:i:s');
         if ($user->save()) {
             $racer->place = strtoupper($racer->place);
             $racer->user_id = $user->id;
             $racer->creation_date = date('Y-m-d H:i:s');
             if ($racer->save()) {
                 Yii::$app->session->setFlash('racerCreated');
                 return $this->redirect(['racer']);
             } else {
                 Yii::$app->session->setFlash('errorRacer', array_values($racer->getFirstErrors())[0]);
             }
         } else {
             Yii::$app->session->setFlash('errorRacer', array_values($user->getFirstErrors())[0]);
         }
     }
     return $this->render('racer', ['user' => $user, 'racer' => $racer, 'races' => $races]);
 }
예제 #2
0
 public function actionView($id)
 {
     $model = Race::findOne($id);
     if (isset($model)) {
         $racer = new Racer();
         if ($racer->load(Yii::$app->request->post())) {
             $racer->race_id = $id;
             $racer->creation_date = date('Y-m-d H:i:s');
             if ($racer->save()) {
                 $this->redirect(['pay', 'id' => $id]);
             } else {
                 print_r($racer->getErrors());
                 die;
             }
         }
         return $this->render('view', ['model' => $model, 'racer' => $racer]);
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }