Exemplo n.º 1
0
 public function actionCrear()
 {
     $msg = null;
     $model = new ValidarCategoria();
     if ($model->load(Yii::$app->request->post()) && Yii::$app->request->isAjax) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         return ActiveForm::validate($model);
     }
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validate()) {
             $tabla = new Categoria();
             $tabla->nombre_categoria = strtolower($model->nombre_categoria);
             $tabla->edad_minima = $model->edad_min;
             $tabla->edad_maxima = $model->edad_max;
             $tabla->id_deporte = $model->deporte;
             $tabla->id_profesor_titular = $model->profesor_titular;
             $tabla->id_profesor_suplente = $model->profesor_suplente;
             if ($tabla->insert()) {
                 $msg = "Categoria registrada con exito!";
                 $model->nombre_categoria = null;
                 $model->edad_max = null;
                 $model->edad_min = null;
             } else {
                 $msg = "No se pudo registrar Categoria.";
             }
         }
     }
     $deporte = ArrayHelper::map(Deporte::find()->all(), 'id_deporte', 'nombre');
     $profesor = ArrayHelper::map(Profesor::find()->all(), 'dni', 'nombre');
     return $this->render("ncategoria", ["msg" => $msg, "model" => $model, "deporte" => $deporte, "profesor" => $profesor]);
 }