예제 #1
0
 public function storePregunta(Request $request)
 {
     try {
         $data = $request->all();
         $pre = new Pregunta();
         $pre->pregunta = $data["pregunta"];
         $pre->requerido = $data["requerido"];
         $pre->tipo = $data["tipo"];
         $pre->seccion = $data["seccion"];
         $pre->save();
         $respuestas = $request->input('respuestas');
         //return $respuestas;
         if (!empty($respuestas)) {
             foreach ($respuestas as &$value) {
                 $res = new Respuesta();
                 $res->respuesta = $value;
                 $res->pregunta = $pre->id;
                 $res->save();
                 //return $value;
             }
         }
         return JsonResponse::create(array('message' => "Pregunta Guardada Correctamente", "request" => $pre), 200);
     } catch (Exception $exc) {
         return JsonResponse::create(array('message' => "No se pudo guardar la Sección", "exception" => $exc->getMessage(), "request" => json_encode($data)), 401);
     }
 }
예제 #2
0
 /**
  * Creates a new Pregunta model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Pregunta();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id, 'codFormulario' => $model->codFormulario]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }