Ver Mensaje Individual
  #30 (permalink)  
Antiguo 05/10/2011, 01:04
miktrv
 
Fecha de Ingreso: julio-2008
Ubicación: Barcelona
Mensajes: 2.100
Antigüedad: 15 años, 9 meses
Puntos: 165
Respuesta: generador de modelos, controladores y vistas

Controller

Código PHP:
Ver original
  1. <?php
  2.  
  3. /*
  4.  
  5.     Description
  6.     @author            miktrv
  7.     @package           Aseguradoras
  8.  
  9. */
  10.  
  11. class Aseguradoras extends CI_Controller {
  12.  
  13.  
  14.     /*
  15.         @package    Aseguradoras
  16.  
  17.         @access     public
  18.         @return     void
  19.     */
  20.  
  21.     public function __construct() {
  22.    
  23.         parent::__construct();
  24.        
  25.     }
  26.  
  27. //----------------------------------------------------------------------------------------------
  28.  
  29.  
  30.     /*
  31.         @package    Aseguradoras
  32.  
  33.         @access     public
  34.         @return     void
  35.     */
  36.  
  37.     public function index() {
  38.    
  39.         $this->lang->load('aseguradoras');
  40.         $this->load->model('Aseguradoras_model');
  41.         $this->load->library('Aseguradoras_entity');
  42.         $this->config->load('aseguradoras_config');
  43.  
  44.         $this->load->library('pagination');
  45.  
  46.         //pagination config
  47.         $total_rows = $this->Aseguradoras_model->get_count();
  48.         $per_page = $this->config->item('per_page');
  49.         $current_page = $this->uri->segment(3);
  50.        
  51.         $config_pagination = array(
  52.             'base_url'    => base_url() . 'aseguradoras/index/',
  53.             'total_rows'  => $total_rows,
  54.             'per_page'    => $per_page,
  55.             'uri_segment' => 3,
  56.         );
  57.    
  58.         $this->pagination->initialize($config_pagination);
  59.    
  60.         $data_view['elements'] = $this->Aseguradoras_model->get_all_extends($limit_left = ($current_page * $per_page), $limit_right = $per_page);
  61.         $data_view['pagination'] = $this->pagination->create_links();
  62.  
  63.         $this->load->view('list_view.phtml', $data_view);
  64.  
  65.     }
  66.  
  67. //----------------------------------------------------------------------------------------------
  68.  
  69.  
  70.     /*
  71.         @package    Aseguradoras
  72.  
  73.         @access     public
  74.         @return     void
  75.         @param      Integer
  76.     */
  77.  
  78.     public function view($id_aseguradora = FALSE) {
  79.    
  80.         $this->lang->load('aseguradoras');
  81.         $this->load->model('Aseguradoras_model');
  82.         $this->load->library('Aseguradoras_entity');
  83.         $this->config->load('aseguradoras_config');
  84.  
  85.  
  86.         if(!$this->Aseguradoras_model->exists_by_id_aseguradora($id_aseguradora)) {
  87.             redirect(base_url() . strtolower(get_class($this)));
  88.             exit();
  89.         }
  90.        
  91.         //create object
  92.         $element = new Aseguradoras_entity();
  93.        
  94.         //set id_aseguradora;
  95.         $element->set_id_aseguradora($id_aseguradora);
  96.        
  97.  
  98.         //load object data
  99.         $element->load_by_id_aseguradora();
  100.            
  101.    
  102.  
  103.            
  104.         //data view
  105.         $data_view['element'] = $element;
  106.  
  107.         $this->load->view('detail_view.phtml', $data_view);
  108.  
  109.     }
  110.  
  111. //----------------------------------------------------------------------------------------------
  112.  
  113.  
  114.     /*
  115.         @package    Aseguradoras
  116.  
  117.         @access     public
  118.         @return     void
  119.     */
  120.  
  121.     public function add() {
  122.    
  123.         $this->load->helper('form');
  124.         $this->load->library('form_validation');
  125.         $this->lang->load('aseguradoras');
  126.         $this->load->library('Aseguradoras_entity');
  127.         $this->load->model('Aseguradoras_model');
  128.         $this->config->load('aseguradoras_config');
  129.  
  130.         $element = new Aseguradoras_entity();
  131.         $data_view['element'] = $element;
  132.         $config_form_validation = $this->config->item('form_validation');
  133.         $this->form_validation->set_rules($config_form_validation);
  134.         if($this->form_validation->run() == FALSE) {
  135.  
  136.             $this->load->view('forms/add_view.phtml', $data_view);
  137.  
  138.         } else {
  139.  
  140.             $aseguradora = $this->input->post('aseguradora');
  141.             $direccion = $this->input->post('direccion');
  142.             $logo = $this->input->post('logo');
  143.             $url_portal = $this->input->post('url_portal');
  144.             $activo = $this->input->post('activo');
  145.  
  146.             if($this->Aseguradoras_model->insert($aseguradora, $direccion, $logo, $url_portal, $activo)) {
  147.  
  148.                 $this->load->view('success_view.phtml');
  149.  
  150.             } else {
  151.  
  152.                 $this->load->view('error_view.phtml');
  153.  
  154.             }
  155.  
  156.         }
  157.  
  158.     }
  159.  
  160. //----------------------------------------------------------------------------------------------
  161.  
  162.  
  163.     /*
  164.         @package    Aseguradoras
  165.  
  166.         @access     public
  167.         @return     void
  168.         @param      Integer
  169.     */
  170.  
  171.     public function edit($id_aseguradora = FALSE) {
  172.    
  173.         $this->load->helper('form');
  174.         $this->load->library('form_validation');
  175.         $this->lang->load('aseguradoras');
  176.         $this->load->library('Aseguradoras_entity');
  177.         $this->load->model('Aseguradoras_model');
  178.         $this->config->load('aseguradoras_config');
  179.  
  180.  
  181.         if(!$this->Aseguradoras_model->exists_by_id_aseguradora($id_aseguradora)) {
  182.             redirect(base_url() . strtolower(get_class($this)));
  183.             exit();
  184.         }
  185.        
  186.         //create object
  187.         $element = new Aseguradoras_entity();
  188.        
  189.         //set id_aseguradora;
  190.         $element->set_id_aseguradora($id_aseguradora);
  191.        
  192.  
  193.         //load object data
  194.         $element->load_by_id_aseguradora();
  195.            
  196.    
  197.  
  198.         //data view
  199.         $data_view['element'] = $element;
  200.  
  201.             $config_form_validation = $this->config->item('form_validation');
  202.         $this->form_validation->set_rules($config_form_validation);
  203.         if($this->form_validation->run() == FALSE) {
  204.  
  205.             $this->load->view('forms/edit_view.phtml', $data_view);
  206.  
  207.         } else {
  208.  
  209.             $element->set_aseguradora($this->input->post('aseguradora'));
  210.             $element->set_direccion($this->input->post('direccion'));
  211.             $element->set_logo($this->input->post('logo'));
  212.             $element->set_url_portal($this->input->post('url_portal'));
  213.             $element->set_activo($this->input->post('activo'));
  214.  
  215.             if($element->update_by_id_aseguradora()) {
  216.  
  217.                 echo 'Updated!!';
  218.  
  219.             } else {
  220.  
  221.                 echo 'No updated...';
  222.  
  223.             }
  224.  
  225.         }
  226.  
  227.     }
  228.  
  229. //----------------------------------------------------------------------------------------------
  230.  
  231.  
  232.     /*
  233.         @package    Aseguradoras
  234.  
  235.         @access     public
  236.         @return     void
  237.         @param      Integer
  238.     */
  239.  
  240.     public function delete($id_aseguradora = FALSE) {
  241.    
  242.         $this->lang->load('aseguradoras');
  243.         $this->load->model('Aseguradoras_model');
  244.         $this->load->library('Aseguradoras_entity');
  245.         $this->config->load('aseguradoras_config');
  246.  
  247.  
  248.         if(!$this->Aseguradoras_model->exists_by_id_aseguradora($id_aseguradora)) {
  249.             redirect(base_url() . strtolower(get_class($this)));
  250.             exit();
  251.         } else {
  252.             $this->Aseguradoras_model->delete_by_id_aseguradora($id_aseguradora);
  253.             redirect(base_url() . strtolower(get_class($this)));
  254.         }
  255.    
  256.     }
  257.  
  258. //----------------------------------------------------------------------------------------------
  259.  
  260. }
__________________
Gracias por el Karma :D

empleo ofertas de trabajo