示例#1
0
 /**
  * Creates a new SubjectTest model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $tests_count = 0;
     $tests = SubjectTest::find()->where(['user_id' => Yii::$app->user->identity->id])->all();
     foreach ($tests as $test) {
         $tests_count++;
     }
     if ($tests_count < 10) {
         $model = new SubjectTest();
         $model->user_id = Yii::$app->user->identity->id;
         if ($model->load(Yii::$app->request->post()) && $model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     } else {
         return $this->redirect('/graduate/user/balance');
     }
 }