/** * Creates a new Career model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate($playerID = null) { $model = new Career(); if (!isset($playerID)) { throw new \yii\web\BadRequestHttpException('Unidentified playerID'); } $player = Player::findOne($playerID); if (!isset($player)) { throw new \yii\web\BadRequestHttpException('Unidentified player model'); } $model->player_id = $playerID; if ($model->load(Yii::$app->request->post()) && $model->save()) { if (Yii::$app->request->isAjax) { $out = ['success' => 'true']; return Json::encode($out); } return $this->redirect(['view', 'id' => $model->id]); } else { if (Yii::$app->request->isAjax) { return $this->renderAjax('create', ['model' => $model]); } return $this->render('create', ['model' => $model]); } }