/** * Creates a new Pay model. * If creation is successful, the browser will be redirected to the 'view' page. * @param integer $user_id * @return mixed */ public function actionCreate($user_id = false) { if ($user_id) { $profile = Profile::findOne(['user_id' => $user_id]); if (!$profile) { throw new HttpException(404); } $model = new Pay(); $model->setScenario('pay-create'); $model->maxBonusBalance = $profile->bonus_balance; $tickets = SeasonTicket::getTicketArray(); //ajax validation if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { $groups = Group::getGroupArray(); return $this->render('create', ['model' => $model, 'profile' => $profile, 'tickets' => $tickets, 'groups' => $groups]); } } else { $searchModel = new UserSearch(); $dataProvider = $searchModel->search(Yii::$app->request->get()); return $this->render('listusers', ['dataProvider' => $dataProvider, 'searchModel' => $searchModel]); } }