Exemple #1
0
 function form_agregar()
 {
     $respuesta = new stdClass();
     $this->form_validation->set_rules('codigo', 'Código', 'trim|required|min_length[5]|max_length[8]|callback_valida_codigo');
     $this->form_validation->set_rules('nombre', 'Nombre', 'trim|required');
     $this->form_validation->set_rules('mision', 'Misión', 'trim|required');
     $this->form_validation->set_rules('entidad_codigo', 'Entidad', 'trim|required');
     if ($this->form_validation->run() == TRUE) {
         $servicio = new Servicio();
         $servicio->codigo = $this->input->post('codigo');
         $servicio->nombre = $this->input->post('nombre');
         $servicio->sigla = $this->input->post('sigla');
         $servicio->url = $this->input->post('url');
         $servicio->responsable = $this->input->post('responsable');
         $servicio->entidad_codigo = $this->input->post('entidad_codigo');
         $servicio->mision = $this->input->post('mision');
         $servicio->sector_codigo = $this->input->post('sector_codigo') ? $this->input->post('sector_codigo') : '00';
         $servicio->setTagsFromArray($this->input->post('tags'));
         $servicio->save();
         $this->session->set_flashdata('message', 'Servicio agregado exitosamente! :)');
         $respuesta->validacion = TRUE;
         $respuesta->redirect = site_url('backend/servicios/');
     } else {
         $respuesta->validacion = FALSE;
         $respuesta->errores = validation_errors('<p class="error">', '</p>');
     }
     echo json_encode($respuesta);
 }