/** * Creates a new Question model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Question(); $parentId = Yii::$app->request->get('parent_id'); if ($model->load(Yii::$app->request->post()) && $model->validate()) { $model->save(false); if (Yii::$app->request->isAjax) { $out = ['success' => 'true']; return Json::encode($out); } return $this->redirect(['view', 'id' => $model->id]); } else { if (isset($parentId)) { $model->parent_id = $parentId; } if (Yii::$app->request->isAjax) { return $this->renderAjax('create', ['model' => $model]); } return $this->render('create', ['model' => $model]); } }
public function actionStep() { $model = new Question(); $answers = []; $count = count(Yii::$app->request->post('Answer', [])); $codeBankCampaign = new CodeBankCampaign(); $codeBankCampaign->load(Yii::$app->request->post()); if (Yii::$app->request->isPost && $model->load(Yii::$app->request->post()) && $model->validate()) { if ($count > 0) { if ($model->qType === '1') { $temp = Yii::$app->request->post('Answer', []); $count = count($temp['answer']); for ($i = 0; $i < $count; $i++) { $answer = new Answer(); $answer->scenario = 'objective'; $answer->answer = $temp['answer'][$i]; $answer->correctObjective = $temp['correctObjective'][$i]; $answer->validate(); $answers[] = $answer; } } } } return $this->render('step', ['model' => $model, 'codeBankCampaign' => $codeBankCampaign, 'answers' => $answers]); }