Example #1
0
 /**
  * Lists all Question models.
  * @return mixed
  */
 public function actionIndex()
 {
     $searchModel = new QuestionSearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }
 /**
  * Updates an existing Question model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if (!Yii::$app->request->isAjax) {
         $answerForm = new Question();
         $searchModel = new QuestionSearch();
         $params = ['QuestionSearch' => ['parent_id' => $model->id]];
         $answersDataProvider = $searchModel->search($params);
         $answersDataProvider->setSort(['defaultOrder' => ['id' => SORT_DESC]]);
     }
     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 (Yii::$app->request->isAjax) {
             return $this->renderAjax('update', ['model' => $model, 'answerForm' => null, 'answersDataProvider' => null]);
         }
         return $this->render('update', ['model' => $model, 'answerForm' => $answerForm, 'answersDataProvider' => $answersDataProvider]);
     }
 }