コード例 #1
0
 /**
  * Creates a new Team model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Team();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
コード例 #2
0
ファイル: TeamController.php プロジェクト: eesast/ts17web
 public function actionJoin($id)
 {
     return $this->redirect(['index']);
     $input = new Team();
     $team = Team::findOne(['id' => $id]);
     if ($input->load(Yii::$app->request->post())) {
         $user = User::findOne(['username' => Yii::$app->user->identity->username]);
         if ($user->teamname != null) {
             return $this->render('error', ['message' => '你已经加入另外一支队伍啦']);
         }
         $team = Team::findOne(['id' => $id]);
         if ($team != null && $team->key == $input->key) {
             if ($team->member1name == '') {
                 $team->member1name = $user->username;
                 $user->teamname = $team->teamname;
                 $team->status++;
             } elseif ($team->member2name == '') {
                 $team->member2name = $user->username;
                 $user->teamname = $team->teamname;
                 $team->status++;
             } elseif ($team->member3name == '') {
                 $team->member3name = $user->username;
                 $user->teamname = $team->teamname;
                 $team->status++;
             } else {
                 return $this->render('error', ['message' => '这支队伍已经有四个人啦']);
             }
             if ($team->save() && $user->save(false)) {
                 return $this->redirect(['view', 'id' => $team->id]);
             }
         } else {
             return $this->render('error', ['message' => '密钥不对。。。']);
         }
     } else {
         return $this->render('join', ['team' => $team, 'model' => $input]);
     }
 }