Foros del Web » Programando para Internet » PHP » CodeIgniter »

generador de modelos, controladores y vistas

Estas en el tema de generador de modelos, controladores y vistas en el foro de CodeIgniter en Foros del Web. Hola buenas, Estoy creando un generador de código para CI y para PHP en general. Me gustaría saber que opináis del código generado. Lo hago ...

  #1 (permalink)  
Antiguo 28/09/2011, 05:54
 
Fecha de Ingreso: julio-2008
Ubicación: Barcelona
Mensajes: 2.100
Antigüedad: 15 años, 8 meses
Puntos: 165
generador de modelos, controladores y vistas

Hola buenas,

Estoy creando un generador de código para CI y para PHP en general.

Me gustaría saber que opináis del código generado. Lo hago a través de tablas SQL. Alguien me pasa tablas? aun me queda mucho e! jaja, si alguien me pasa una tabla para generar el código que no se pase con los campos o sera mucho código
__________________
Gracias por el Karma :D

empleo ofertas de trabajo
  #2 (permalink)  
Antiguo 28/09/2011, 07:07
Avatar de Ronruby  
Fecha de Ingreso: julio-2008
Ubicación: 18°30'N, 69°59'W
Mensajes: 4.879
Antigüedad: 15 años, 8 meses
Puntos: 416
Respuesta: generador de modelos, controladores y vistas

Cita:
Iniciado por miktrv Ver Mensaje
Hola buenas,

Estoy creando un generador de código para CI y para PHP en general.

Me gustaría saber que opináis del código generado. Lo hago a través de tablas SQL. Alguien me pasa tablas? aun me queda mucho e! jaja, si alguien me pasa una tabla para generar el código que no se pase con los campos o sera mucho código
No entendí nada :S
  #3 (permalink)  
Antiguo 28/09/2011, 07:24
 
Fecha de Ingreso: julio-2008
Ubicación: Barcelona
Mensajes: 2.100
Antigüedad: 15 años, 8 meses
Puntos: 165
Respuesta: generador de modelos, controladores y vistas

He creado un código para generar modelos, librerias, modelos y vistas a través de una tabla mysql.

y quiero que alguien me pase una tabla para devolver el ejemplo creado con el generador, para que tenga un poco de gracias y no hacerlo con algo mio..

Un saludo!
__________________
Gracias por el Karma :D

empleo ofertas de trabajo
  #4 (permalink)  
Antiguo 28/09/2011, 07:43
Avatar de Eleazan  
Fecha de Ingreso: abril-2008
Ubicación: Ibiza
Mensajes: 1.879
Antigüedad: 15 años, 11 meses
Puntos: 326
Respuesta: generador de modelos, controladores y vistas

Prueba con esta:

Código MySQL:
Ver original
  1. CREATE TABLE IF NOT EXISTS `grupostarifa` (
  2.   `id` int(11) NOT NULL AUTO_INCREMENT,
  3.   `grupo` varchar(5) NOT NULL,
  4.   `nombre` varchar(100) NOT NULL,
  5.   `emin` int(11) NOT NULL,
  6.   `apermiso` int(11) NOT NULL,
  7.   `activo` int(11) DEFAULT '1',
  8.   `franquicia` decimal(10,2) NOT NULL,
  9.   `id_grupovehiculos` int(11) NOT NULL,
  10.   `created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  11.   `modified_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP,
  12.   PRIMARY KEY (`id`)
__________________
>> Eleazan's Source
>> @Eleazan
  #5 (permalink)  
Antiguo 28/09/2011, 07:51
Avatar de masterpuppet
Software Craftsman
 
Fecha de Ingreso: enero-2008
Ubicación: Montevideo, Uruguay
Mensajes: 3.550
Antigüedad: 16 años, 2 meses
Puntos: 845
Respuesta: generador de modelos, controladores y vistas

Te dejo una referencia http://dev.mysql.com/doc/index-other.html, igual te sugiero que busques ejemplos de schemas seguro que hay alguno que otro.

Saludos.
__________________
http://es.phptherightway.com/
thats us riders :)
  #6 (permalink)  
Antiguo 29/09/2011, 00:56
 
Fecha de Ingreso: julio-2008
Ubicación: Barcelona
Mensajes: 2.100
Antigüedad: 15 años, 8 meses
Puntos: 165
Respuesta: generador de modelos, controladores y vistas

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`id` INT(11) NOT NULL AUTO_INCREMENT, Â `grupo` VARCHAR(5) NOT NULL, Â `nomb' at line 2
__________________
Gracias por el Karma :D

empleo ofertas de trabajo
  #7 (permalink)  
Antiguo 29/09/2011, 09:18
Avatar de Ronruby  
Fecha de Ingreso: julio-2008
Ubicación: 18°30'N, 69°59'W
Mensajes: 4.879
Antigüedad: 15 años, 8 meses
Puntos: 416
Respuesta: generador de modelos, controladores y vistas

La consulta que te envio Eleazan no tiene errores.

Trata con esta:
Código SQL:
Ver original
  1. CREATE TABLE IF NOT EXISTS `blog_users` (
  2.   `userID` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
  3.   `username` CHAR(20) NOT NULL,
  4.   `password` CHAR(40) NOT NULL,
  5.   `email` CHAR(255) NOT NULL,
  6.   PRIMARY KEY (`userID`),
  7.   UNIQUE KEY `username` (`username`),
  8.   UNIQUE KEY `email` (`email`)
  9. ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
  #8 (permalink)  
Antiguo 29/09/2011, 11:35
 
Fecha de Ingreso: julio-2008
Ubicación: Barcelona
Mensajes: 2.100
Antigüedad: 15 años, 8 meses
Puntos: 165
Respuesta: generador de modelos, controladores y vistas

Entonces lo que he posteado que es¿?

Probaré con tu ejemplo, un saludo!
__________________
Gracias por el Karma :D

empleo ofertas de trabajo
  #9 (permalink)  
Antiguo 29/09/2011, 11:37
 
Fecha de Ingreso: julio-2008
Ubicación: Barcelona
Mensajes: 2.100
Antigüedad: 15 años, 8 meses
Puntos: 165
Respuesta: generador de modelos, controladores y vistas

Me da error tu sql tambien..


#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`userID` int(11) UNSIGNED NOT NULL AUTO_INCREMENT, Â `username` char(20) NOT N' at line 2
__________________
Gracias por el Karma :D

empleo ofertas de trabajo
  #10 (permalink)  
Antiguo 29/09/2011, 11:53
 
Fecha de Ingreso: julio-2008
Ubicación: Barcelona
Mensajes: 2.100
Antigüedad: 15 años, 8 meses
Puntos: 165
Respuesta: generador de modelos, controladores y vistas

Postearé el código con dos tablas creadas por mi mismo.. no se porque no me deja crear las tablas que me pasais... si alguien quiere pasarme algo lo hago con sus tablas,
__________________
Gracias por el Karma :D

empleo ofertas de trabajo
  #11 (permalink)  
Antiguo 29/09/2011, 12:22
Avatar de maycolalvarez
Colaborador
 
Fecha de Ingreso: julio-2008
Ubicación: Caracas
Mensajes: 12.120
Antigüedad: 15 años, 8 meses
Puntos: 1532
Respuesta: generador de modelos, controladores y vistas

te voy a dar mi opinión:
dependiendo del proyecto un generador de código puede resultar muy útil para automatizar tareas repetitivas, pero has de tener en cuenta que existen ciertas tareas que por más vueltas que le des no se pueden automatizar, es por ello que si dicho generador debe ser completamente desacoplable, de manera que puedas utilizarlo y omitirlo según el caso.
__________________
¡Por favor!: usa el highlight para mostrar código
El que busca, encuentra...
  #12 (permalink)  
Antiguo 29/09/2011, 12:45
 
Fecha de Ingreso: julio-2008
Ubicación: Barcelona
Mensajes: 2.100
Antigüedad: 15 años, 8 meses
Puntos: 165
Respuesta: generador de modelos, controladores y vistas

Hola buenas,

Estoy totalmente de acuerdo. Este generador esta separado del proyecto, y se puede ejecutar por módulos, cada uno de ellos configurable. Puedo generar solo vistas, solo modelos, solo librerías o solo controladores. Además, el código generado, es totalmente personalizable, aunque en la mayoría de casos no haría falta tocarlo. La gran ventaja bajo mi punto de vista, es que en lugar de tener un orm que trabaja y consume recursos tras cada operación con la bbdd, al tener un código a medida que ya esta escrito únicamente para lo que necesita, es muy rápido, y sigue la linea de CodeIgniter.

Un saludo y gracias por el interés!
__________________
Gracias por el Karma :D

empleo ofertas de trabajo
  #13 (permalink)  
Antiguo 29/09/2011, 14:39
Avatar de _ssx  
Fecha de Ingreso: mayo-2003
Ubicación: mX
Mensajes: 683
Antigüedad: 20 años, 10 meses
Puntos: 60
Respuesta: generador de modelos, controladores y vistas

Código PHP:
CREATE TABLE Aseguradoras (
  
id_aseguradora int(11unsigned NOT NULL AUTO_INCREMENT,
  
aseguradora varchar(120NOT NULL COMMENT 'Es el nombre de la aseguradora',
  
direccion mediumtext NOT NULL COMMENT 'Dirección de la aseguradora',
  
logo varchar(100NOT NULL COMMENT 'Contiene el nombre del archivo jpg del logo',
  
url_portal varchar(255) DEFAULT NULL,
  
activo tinyint(1NOT NULL DEFAULT '1' COMMENT 'Permite saber si el elemento sigue activo (1) o no (0) en la BD.',
  
PRIMARY KEY (id_aseguradora)
ENGINE=InnoDB  DEFAULT CHARSET=utf8
Si tampoco ejecuta esa Query creo que tambien debes de poner los requerimentos especificos de tu motor de MySql o el que estes usando
__________________
Escribe tu código de forma que refleje, y saque a relucir,lo mejor de tu carácter personal
www.oscararzola.com/blog
Principios de un programador
  #14 (permalink)  
Antiguo 29/09/2011, 16:32
 
Fecha de Ingreso: julio-2008
Ubicación: Barcelona
Mensajes: 2.100
Antigüedad: 15 años, 8 meses
Puntos: 165
Respuesta: generador de modelos, controladores y vistas

Buenas,

El generador no esta enlazado a una versión en concreto de mysql, el problema de crear las tablas me lo tira el phpmyadmin, es decir, el generador no interviene en el proceso de creación de tablas.

Este SQL si me lo ha cogido correctamente! pegare el código generado por partes mañana, espero vuestros comentarios al respecto, aun quedan mejoras pendientes pero esta avanzado,

Un saludo
__________________
Gracias por el Karma :D

empleo ofertas de trabajo
  #15 (permalink)  
Antiguo 30/09/2011, 01:06
 
Fecha de Ingreso: julio-2008
Ubicación: Barcelona
Mensajes: 2.100
Antigüedad: 15 años, 8 meses
Puntos: 165
Respuesta: generador de modelos, controladores y vistas

Aquí dejo el código generado:


Controlador:

Código PHP:
<?php

/*

  Description
  @author    Miguel Ángel Navarro
  @package    Aseguradoras

 */

class Aseguradoras extends CI_Controller {
    
/*
      @package    Aseguradoras

      @access     public
      @return     void
     */

    
public function __construct() {

        
parent::__construct();
    }

//----------------------------------------------------------------------------------------------


    /*
      @package    Aseguradoras

      @access     public
      @return     void
     */

    
public function index() {

        
$this->lang->load('aseguradoras');
        
$this->load->model('Aseguradoras_model');
        
$this->load->library('Aseguradoras_entity');

        
$this->load->library('pagination');

        
//pagination config
        
$total_rows $this->Aseguradoras_model->get_count();
        
$per_page 20;
        
$current_page $this->uri->segment(3);

        
$config_pagination = array(
            
'base_url' => base_url() . 'aseguradoras/index/',
            
'total_rows' => $total_rows,
            
'per_page' => $per_page,
            
'uri_segment' => 3,
        );

        
$this->pagination->initialize($config_pagination);

        
$data_view['elements'] = $this->Aseguradoras_model->get_all_extends($limit_left = ($current_page $per_page), $limit_right $per_page);
        
$data_view['pagination'] = $this->pagination->create_links();

        
$this->load->view('list_view.phtml'$data_view);
    }

//----------------------------------------------------------------------------------------------


    /*
      @package    Aseguradoras

      @access     public
      @return     void
     */

    
public function add() {

        
$this->load->helper('form');
        
$this->load->library('form_validation');
        
$this->lang->load('aseguradoras');
        
$this->load->model('Aseguradoras_model');

        
$config_form_validation = array(
            array(
                
'field' => 'aseguradora',
                
'label' => $this->lang->line('label.aseguradora'),
                
'rules' => 'required|max_length[120]'
            
),
            array(
                
'field' => 'direccion',
                
'label' => $this->lang->line('label.direccion'),
                
'rules' => 'required'
            
),
            array(
                
'field' => 'logo',
                
'label' => $this->lang->line('label.logo'),
                
'rules' => 'required|max_length[100]'
            
),
            array(
                
'field' => 'url_portal',
                
'label' => $this->lang->line('label.url_portal'),
                
'rules' => 'max_length[255]'
            
),
            array(
                
'field' => 'activo',
                
'label' => $this->lang->line('label.activo'),
                
'rules' => 'max_length[1]'
            
),
        );

        
$data_view['form_action'] = 'Aseguradoras/add/';
        
$this->form_validation->set_rules($config_form_validation);
        if (
$this->form_validation->run() == FALSE) {

            
$this->load->view('forms/add_view.phtml'$data_view);
        } else {

            
$aseguradora $this->input->post('aseguradora');
            
$direccion $this->input->post('direccion');
            
$logo $this->input->post('logo');
            
$url_portal $this->input->post('url_portal');
            
$activo $this->input->post('activo');

            if (
$this->Aseguradoras_model->insert($aseguradora$direccion$logo$url_portal$activo)) {

                
$this->load->view('success_view.phtml');
            } else {

                
$this->load->view('error_view.phtml');
            }
        }
    }

//----------------------------------------------------------------------------------------------


    /*
      @package    Aseguradoras

      @access     public
      @return     void
      @param
     */

    
public function edit($id_aseguradora '') {

        
$this->load->helper('form');
        
$this->load->library('form_validation');
        
$this->lang->load('aseguradoras');
        
$this->load->model('Aseguradoras_model');

        if (!
$this->Aseguradoras_model->exists_by_id_aseguradora($id_aseguradora)) {
            
redirect(base_url() . strtolower(get_class($this)));
        }

        
$config_form_validation = array(
            array(
                
'field' => 'aseguradora',
                
'label' => $this->lang->line('label.aseguradora'),
                
'rules' => 'required|max_length[120]'
            
),
            array(
                
'field' => 'direccion',
                
'label' => $this->lang->line('label.direccion'),
                
'rules' => 'required'
            
),
            array(
                
'field' => 'logo',
                
'label' => $this->lang->line('label.logo'),
                
'rules' => 'required|max_length[100]'
            
),
            array(
                
'field' => 'url_portal',
                
'label' => $this->lang->line('label.url_portal'),
                
'rules' => 'max_length[255]'
            
),
            array(
                
'field' => 'activo',
                
'label' => $this->lang->line('label.activo'),
                
'rules' => 'max_length[1]'
            
),
        );

        
$data_view['form_action'] = 'Aseguradoras/edit/';
        
$this->form_validation->set_rules($config_form_validation);
        if (
$this->form_validation->run() == FALSE) {

            
$this->load->view('forms/add_view.phtml'$data_view);
        } else {

            
$aseguradora $this->input->post('aseguradora');
            
$direccion $this->input->post('direccion');
            
$logo $this->input->post('logo');
            
$url_portal $this->input->post('url_portal');
            
$activo $this->input->post('activo');

            if (
$this->Aseguradoras_model->insert($aseguradora$direccion$logo$url_portal$activo)) {

                
$this->load->view('success_view.phtml');
            } else {

                
$this->load->view('error_view.phtml');
            }
        }
    }

//----------------------------------------------------------------------------------------------
}
De los controladores falta el método edit y delete, que aún los tengo acabados.
__________________
Gracias por el Karma :D

empleo ofertas de trabajo
  #16 (permalink)  
Antiguo 30/09/2011, 01:09
 
Fecha de Ingreso: julio-2008
Ubicación: Barcelona
Mensajes: 2.100
Antigüedad: 15 años, 8 meses
Puntos: 165
Respuesta: generador de modelos, controladores y vistas

Modelo

Código PHP:
<?php

/*

  Description
  @author    _ssx
  @package    Aseguradoras

 */

class Aseguradoras_model extends CI_Model {
    
/*
      @package    Aseguradoras

      @access     public
      @return     void
     */

    
public function __construct() {

        
parent::__construct();
    }

//----------------------------------------------------------------------------------------------


    /*
      @package    Aseguradoras

      @access     public
      @return     array
      @param      String
     */

    
public function get_all($sql_extra '') {

        
$out = array();

        
$sql '
        
            SELECT
                ' 
TABLE_ASEGURADORAS_FIELD_ID_ASEGURADORA ', 
            ' 
TABLE_ASEGURADORAS_FIELD_ASEGURADORA ', 
            ' 
TABLE_ASEGURADORAS_FIELD_DIRECCION ', 
            ' 
TABLE_ASEGURADORAS_FIELD_LOGO ', 
            ' 
TABLE_ASEGURADORAS_FIELD_URL_PORTAL ', 
            ' 
TABLE_ASEGURADORAS_FIELD_ACTIVO '

            FROM ' 
TABLE_ASEGURADORAS '

        '
;

        if (!empty(
$sql_extra)) {
            
$sql .= ' ' $sql_extra;
        }

        
$query mysql_query($sql);

        while (
$row mysql_fetch_array($query)) {

            
$temp_object = new Aseguradoras_entity();
            
$temp_object->set_id_aseguradora($row[TABLE_ASEGURADORAS_FIELD_ID_ASEGURADORA]);
            
$temp_object->set_aseguradora($row[TABLE_ASEGURADORAS_FIELD_ASEGURADORA]);
            
$temp_object->set_direccion($row[TABLE_ASEGURADORAS_FIELD_DIRECCION]);
            
$temp_object->set_logo($row[TABLE_ASEGURADORAS_FIELD_LOGO]);
            
$temp_object->set_url_portal($row[TABLE_ASEGURADORAS_FIELD_URL_PORTAL]);
            
$temp_object->set_activo($row[TABLE_ASEGURADORAS_FIELD_ACTIVO]);

            
//add object to array
            
array_push($out$temp_object);
        }

        return 
$out;
    }

//----------------------------------------------------------------------------------------------


    /*
      @package    Aseguradoras

      @access     public
      @return     array
      @param      Integer
      @param      Integer
      @param      String
     */

    
public function get_all_extends($limit_left FALSE$limit_right FALSE$condition '') {

        
$sql_extra '';

        if (!empty(
$condition)) {
            
$sql_extra .= ' WHERE ' $condition;
        }

        if (
is_numeric($limit_left)) {
            
$sql_extra .= ' LIMIT ' $limit_left;
        }

        if (
is_numeric($limit_right) and is_numeric($limit_left)) {
            
$sql_extra .= ', ' $limit_right;
        }


        return 
$this->get_all($sql_extra);
    }

//----------------------------------------------------------------------------------------------


    /*
      @package    Aseguradoras

      @access     public
      @return     integer
      @param      String
     */

    
public function get_count($condition '') {

        
$out 0;

        
$sql =
                
'   
            SELECT 
            COUNT(' 
TABLE_ASEGURADORAS_FIELD_ID_ASEGURADORA ') AS count 
            FROM ' 
TABLE_ASEGURADORAS 

        '
;

        if (!empty(
$condition)) {
            
$sql .= ' WHERE ' $condition;
        }

        
$query mysql_query($sql);

        
$row mysql_fetch_array($query);

        
$out $row['count'];

        return 
$out;
    }

//----------------------------------------------------------------------------------------------


    /*
      @package    Aseguradoras

      @access     public
      @return     Aseguradoras
      @param      Integer
     */

    
public function get_by_id_aseguradora($id_aseguradora FALSE) {

        
$Aseguradoras_entity = new Aseguradoras_entity();

        if (
$id_aseguradora) {

            
$Aseguradoras_entity->set_id_aseguradora($id_aseguradora);

            
$sql '

            SELECT
                    ' 
TABLE_ASEGURADORAS_FIELD_ASEGURADORA ', 
                ' 
TABLE_ASEGURADORAS_FIELD_DIRECCION ', 
                ' 
TABLE_ASEGURADORAS_FIELD_LOGO ', 
                ' 
TABLE_ASEGURADORAS_FIELD_URL_PORTAL ', 
                ' 
TABLE_ASEGURADORAS_FIELD_ACTIVO '

            FROM ' 
TABLE_ASEGURADORAS '
            WHERE ' 
TABLE_ASEGURADORAS_FIELD_ID_ASEGURADORA ' = \'' $Aseguradoras_entity->get_id_aseguradora() . '\'

            '
;

            
$query mysql_query($sql);
            
$row mysql_fetch_array($query);
            
$Aseguradoras_entity->set_aseguradora($row[TABLE_ASEGURADORAS_FIELD_ASEGURADORA]);
            
$Aseguradoras_entity->set_direccion($row[TABLE_ASEGURADORAS_FIELD_DIRECCION]);
            
$Aseguradoras_entity->set_logo($row[TABLE_ASEGURADORAS_FIELD_LOGO]);
            
$Aseguradoras_entity->set_url_portal($row[TABLE_ASEGURADORAS_FIELD_URL_PORTAL]);
            
$Aseguradoras_entity->set_activo($row[TABLE_ASEGURADORAS_FIELD_ACTIVO]);
        }

        return 
$Aseguradoras_entity;
    }

//----------------------------------------------------------------------------------------------


    /*
      @package    Aseguradoras

      @access     public
      @return     boolean
      @param      Integer
     */

    
public function exists_by_id_aseguradora($id_aseguradora FALSE) {

        
$out FALSE;

        if (
$id_aseguradora) {

            
$sql =
                    
'   
                SELECT 
                COUNT(' 
TABLE_ASEGURADORAS_FIELD_ID_ASEGURADORA ') AS count 
                FROM ' 
TABLE_ASEGURADORAS 
                WHERE ' 
TABLE_ASEGURADORAS_FIELD_ID_ASEGURADORA ' = \'' $id_aseguradora '\'

            '
;

            
$query mysql_query($sql);

            
$row mysql_fetch_array($query);

            if (
$row['count'] == 1) {

                
$out TRUE;
            }
        }

        return 
$out;
    }

//----------------------------------------------------------------------------------------------


    /*
      @package    Aseguradoras

      @access     public
      @return     boolean
      @param      Integer
     */

    
public function delete_by_id_aseguradora($id_aseguradora FALSE) {

        
$out FALSE;

        if (
$id_aseguradora) {

            
$sql '

                DELETE FROM ' 
TABLE_ASEGURADORAS '
                WHERE ' 
TABLE_ASEGURADORAS_FIELD_ID_ASEGURADORA ' = \'' $id_aseguradora '\'
                LIMIT 1

            '
;

            
mysql_query($sql);

            if (
mysql_affected_rows() == 1) {

                
$out TRUE;
            }
        }

        return 
$out;
    }

//----------------------------------------------------------------------------------------------


    /*
      @package    Aseguradoras

      @access     public
      @return     boolean
      @param      String
      @param      MEDIUMTEXT
      @param      String
      @param      String
      @param      Boolean
     */

    
public function insert($aseguradora ''$direccion ''$logo ''$url_portal ''$activo 1) {

        
$out FALSE;

        if (
$activo) {
            
$activo 1;
        } else {
            
$activo 0;
        }


        
$sql '

        INSERT INTO ' 
TABLE_ASEGURADORAS '
        (
            ' 
TABLE_ASEGURADORAS_FIELD_ASEGURADORA ', 
            ' 
TABLE_ASEGURADORAS_FIELD_DIRECCION ', 
            ' 
TABLE_ASEGURADORAS_FIELD_LOGO ', 
            ' 
TABLE_ASEGURADORAS_FIELD_URL_PORTAL ', 
            ' 
TABLE_ASEGURADORAS_FIELD_ACTIVO '

        )
        VALUES
        (
            \'' 
$aseguradora '\', 
            \'' 
$direccion '\', 
            \'' 
$logo '\', 
            \'' 
$url_portal '\', 
            \'' 
$activo '\'

        )
        ;
        '
;

        if (
mysql_query($sql) and mysql_affected_rows() == 1) {
            
$out TRUE;
        }

        return 
$out;
    }

//----------------------------------------------------------------------------------------------


    /*
      @package    Aseguradoras

      @access     public
      @return     boolean
      @param      String
      @param      MEDIUMTEXT
      @param      String
      @param      String
      @param      Boolean
     */

    
public function insert_extends($aseguradora ''$direccion ''$logo ''$url_portal ''$activo 1) {
        return 
$this->insert($aseguradora$direccion$logo$url_portal$activo);
    }

//----------------------------------------------------------------------------------------------
}

De los modelos me falta cambiar algún tipo de dato como el mediumtext que no lo usoy en generallas consultas a la base de datos irán con la librería de CIahora están asi pero el generador se puede configurar para cambiar el acceso BBDD fácilmenteDe hechola idea es que pudas colocar lo que quierasasí cada persona puede usar sus propias librerias si asi lo desea
__________________
Gracias por el Karma :D

empleo ofertas de trabajo
  #17 (permalink)  
Antiguo 30/09/2011, 01:13
 
Fecha de Ingreso: julio-2008
Ubicación: Barcelona
Mensajes: 2.100
Antigüedad: 15 años, 8 meses
Puntos: 165
Respuesta: generador de modelos, controladores y vistas

Libreria:

Código PHP:
<?php

/*

  Description
  @author    _ssx
  @package    Aseguradoras

 */

class Aseguradoras_entity {

    private 
$id_aseguradora;
    public 
$aseguradora;
    public 
$direccion;
    public 
$logo;
    public 
$url_portal;
    public 
$activo;

    
/*
      @package    Aseguradoras

      @access     public
      @return     void
      @param      Integer
     */

    
public function __construct($id_aseguradora FALSE) {

        if (
$id_aseguradora) {
            
$this->id_aseguradora $id_aseguradora;
            
$this->load();
        } else {
            
$this->activo 1;
        }
    }

//----------------------------------------------------------------------------------------------


    /*
      @package    Aseguradoras

      @access     public
      @return     void
      @param      Integer
     */

    
public function set_id_aseguradora($id_aseguradora) {

        
$this->id_aseguradora $id_aseguradora;
    }

//----------------------------------------------------------------------------------------------


    /*
      @package    Aseguradoras

      @access     public
      @return     Integer
     */

    
public function get_id_aseguradora() {

        return 
$this->id_aseguradora;
    }

//----------------------------------------------------------------------------------------------


    /*
      @package    Aseguradoras

      @access     public
      @return     void
      @param      String
     */

    
public function set_aseguradora($aseguradora) {

        
$this->aseguradora $aseguradora;
    }

//----------------------------------------------------------------------------------------------


    /*
      @package    Aseguradoras

      @access     public
      @return     String
     */

    
public function get_aseguradora() {

        return 
$this->aseguradora;
    }

//----------------------------------------------------------------------------------------------


    /*
      @package    Aseguradoras

      @access     public
      @return     void
      @param      MEDIUMTEXT
     */

    
public function set_direccion($direccion) {

        
$this->direccion $direccion;
    }

//----------------------------------------------------------------------------------------------


    /*
      @package    Aseguradoras

      @access     public
      @return     MEDIUMTEXT
     */

    
public function get_direccion() {

        return 
$this->direccion;
    }

//----------------------------------------------------------------------------------------------


    /*
      @package    Aseguradoras

      @access     public
      @return     void
      @param      String
     */

    
public function set_logo($logo) {

        
$this->logo $logo;
    }

//----------------------------------------------------------------------------------------------


    /*
      @package    Aseguradoras

      @access     public
      @return     String
     */

    
public function get_logo() {

        return 
$this->logo;
    }

//----------------------------------------------------------------------------------------------


    /*
      @package    Aseguradoras

      @access     public
      @return     void
      @param      String
     */

    
public function set_url_portal($url_portal) {

        
$this->url_portal $url_portal;
    }

//----------------------------------------------------------------------------------------------


    /*
      @package    Aseguradoras

      @access     public
      @return     String
     */

    
public function get_url_portal() {

        return 
$this->url_portal;
    }

//----------------------------------------------------------------------------------------------


    /*
      @package    Aseguradoras

      @access     public
      @return     void
      @param      Boolean
     */

    
public function set_activo($activo 1) {

        
$this->activo $activo;
    }

//----------------------------------------------------------------------------------------------


    /*
      @package    Aseguradoras

      @access     public
      @return     Boolean
     */

    
public function get_activo() {

        return 
$this->activo;
    }

//----------------------------------------------------------------------------------------------


    /*
      @package    Aseguradoras

      @access     public
      @return     void
     */

    
public function load() {


        
$sql '
        
        SELECT
            ' 
TABLE_ASEGURADORAS_FIELD_ASEGURADORA ', 
            ' 
TABLE_ASEGURADORAS_FIELD_DIRECCION ', 
            ' 
TABLE_ASEGURADORAS_FIELD_LOGO ', 
            ' 
TABLE_ASEGURADORAS_FIELD_URL_PORTAL ', 
            ' 
TABLE_ASEGURADORAS_FIELD_ACTIVO '

        FROM ' 
TABLE_ASEGURADORAS '
        WHERE ' 
TABLE_ASEGURADORAS_FIELD_ID_ASEGURADORA ' = \'' $this->id_aseguradora '\'
   
        '
;
        
$query mysql_query($sql);
        
$row mysql_fetch_array($query);
        
$this->aseguradora $row[TABLE_ASEGURADORAS_FIELD_ASEGURADORA];
        
$this->direccion $row[TABLE_ASEGURADORAS_FIELD_DIRECCION];
        
$this->logo $row[TABLE_ASEGURADORAS_FIELD_LOGO];
        
$this->url_portal $row[TABLE_ASEGURADORAS_FIELD_URL_PORTAL];
        
$this->activo $row[TABLE_ASEGURADORAS_FIELD_ACTIVO];
    }

//----------------------------------------------------------------------------------------------


    /*
      @package    Aseguradoras

      @access     public
      @return     boolean
     */

    
public function insert() {

        
$out FALSE;

        
$sql '

        INSERT INTO ' 
TABLE_ASEGURADORAS '
        (
            ' 
TABLE_ASEGURADORAS_FIELD_ASEGURADORA ', 
            ' 
TABLE_ASEGURADORAS_FIELD_DIRECCION ', 
            ' 
TABLE_ASEGURADORAS_FIELD_LOGO ', 
            ' 
TABLE_ASEGURADORAS_FIELD_URL_PORTAL ', 
            ' 
TABLE_ASEGURADORAS_FIELD_ACTIVO '

        )
        VALUES
        (
            \'' 
$this->aseguradora '\', 
            \'' 
$this->direccion '\', 
            \'' 
$this->logo '\', 
            \'' 
$this->url_portal '\', 
            \'' 
$this->activo '\'

        )
        ;
        '
;

        if (
mysql_query($sql) and mysql_affected_rows() == 1) {
            
$out TRUE;
        }
        
$this->id_aseguradora mysql_insert_id();

        return 
$out;
    }

//----------------------------------------------------------------------------------------------


    /*
      @package    Aseguradoras

      @access     public
      @return     boolean
     */

    
public function update() {

        
$out FALSE;

        
$sql '
        UPDATE ' 
TABLE_ASEGURADORAS ' SET  
            ' 
TABLE_ASEGURADORAS_FIELD_ASEGURADORA ' = \'' $this->aseguradora '\', 
            ' 
TABLE_ASEGURADORAS_FIELD_DIRECCION ' = \'' $this->direccion '\', 
            ' 
TABLE_ASEGURADORAS_FIELD_LOGO ' = \'' $this->logo '\', 
            ' 
TABLE_ASEGURADORAS_FIELD_URL_PORTAL ' = \'' $this->url_portal '\', 
            ' 
TABLE_ASEGURADORAS_FIELD_ACTIVO ' = \'' $this->activo '\'
         WHERE ' 
TABLE_ASEGURADORAS_FIELD_ID_ASEGURADORA ' = \'' $this->id_aseguradora '\'
        '
;


        if (
mysql_query($sql) and mysql_affected_rows() == 1) {
            
$out TRUE;
        }

        return 
$out;
    }

//----------------------------------------------------------------------------------------------


    /*
      Save the data in database, check if register exists for create or update

      @package    Aseguradoras

      @access     public
      @return     boolean
     */

    /*
      public function save() {

      if($this->get_id_aseguradora()) {
      return $this->update();
      } else {
      return $this->insert();
      }

      }
     */

//----------------------------------------------------------------------------------------------


    /*
      Save data when object deleted in memory! :D

      @package    Aseguradoras

      @access     public
      @return     void
     */

    /*
      public function __destruct() {

      $this->save();

      }
     */

//----------------------------------------------------------------------------------------------
}
__________________
Gracias por el Karma :D

empleo ofertas de trabajo
  #18 (permalink)  
Antiguo 30/09/2011, 01:15
 
Fecha de Ingreso: julio-2008
Ubicación: Barcelona
Mensajes: 2.100
Antigüedad: 15 años, 8 meses
Puntos: 165
Respuesta: generador de modelos, controladores y vistas

En las librerías he dejado dos métodos comentados por defecto por si alguien los usa

Database schema:

Código PHP:
Ver original
  1. <?php
  2.  
  3.     define('TABLE_ASEGURADORAS', 'Aseguradoras');
  4.  
  5.     define('TABLE_ASEGURADORAS_FIELD_ID_ASEGURADORA', 'id_aseguradora');
  6.     define('TABLE_ASEGURADORAS_FIELD_ASEGURADORA', 'aseguradora');
  7.     define('TABLE_ASEGURADORAS_FIELD_DIRECCION', 'direccion');
  8.     define('TABLE_ASEGURADORAS_FIELD_LOGO', 'logo');
  9.     define('TABLE_ASEGURADORAS_FIELD_URL_PORTAL', 'url_portal');
  10.     define('TABLE_ASEGURADORAS_FIELD_ACTIVO', 'activo');
__________________
Gracias por el Karma :D

empleo ofertas de trabajo
  #19 (permalink)  
Antiguo 30/09/2011, 01:16
 
Fecha de Ingreso: julio-2008
Ubicación: Barcelona
Mensajes: 2.100
Antigüedad: 15 años, 8 meses
Puntos: 165
Respuesta: generador de modelos, controladores y vistas

Vistas (por el momento solo genero add y edit que son iguales)

Código PHP:
<?php
$config_form 
= array(
    
'aseguradora' => array(
        
'name' => 'aseguradora',
        
'id' => 'aseguradora',
        
'value' => set_value('aseguradora'''),
        
'maxlenght' => '120',
    ),
    
'direccion' => array(
        
'name' => 'direccion',
        
'id' => 'direccion',
        
'value' => set_value('direccion'''),
        
'maxlenght' => '0',
    ),
    
'logo' => array(
        
'name' => 'logo',
        
'id' => 'logo',
        
'value' => set_value('logo'''),
        
'maxlenght' => '100',
    ),
    
'url_portal' => array(
        
'name' => 'url_portal',
        
'id' => 'url_portal',
        
'value' => set_value('url_portal'''),
        
'maxlenght' => '255',
    ),
    
'activo' => array(
        
'name' => 'activo',
        
'id' => 'activo',
        
'value' => '1',
        
'checked' => set_checkbox('activo''1'),
    ),
);
?>
<?php 
echo validation_errors(); ?>
<?php 
echo form_open($form_action); ?>
<table>
    <tr>
        <td><?php echo form_label($this->lang->line('label.aseguradora')); ?></td>
        <td><?php echo form_input($config_form['aseguradora']); ?></td>
    </tr>
    <tr>
        <td><?php echo form_label($this->lang->line('label.direccion')); ?></td>
        <td><?php echo form_input($config_form['direccion']); ?></td>
    </tr>
    <tr>
        <td><?php echo form_label($this->lang->line('label.logo')); ?></td>
        <td><?php echo form_input($config_form['logo']); ?></td>
    </tr>
    <tr>
        <td><?php echo form_label($this->lang->line('label.url_portal')); ?></td>
        <td><?php echo form_input($config_form['url_portal']); ?></td>
    </tr>
    <tr>
        <td><?php echo form_label($this->lang->line('label.activo')); ?></td>
        <td><?php echo form_checkbox($config_form['activo']); ?></td>
    </tr>
    <tr>
        <td colspan="2">
<?php echo form_submit('mysubmit''Submit!'); ?></td>
    </tr>
</table>
</form>
__________________
Gracias por el Karma :D

empleo ofertas de trabajo
  #20 (permalink)  
Antiguo 30/09/2011, 01:19
 
Fecha de Ingreso: julio-2008
Ubicación: Barcelona
Mensajes: 2.100
Antigüedad: 15 años, 8 meses
Puntos: 165
Respuesta: generador de modelos, controladores y vistas

Por último language:

Código PHP:
<?php

    $lang
['label.id_aseguradora'] = 'Id aseguradora';
    
$lang['label.aseguradora'] = 'Aseguradora';
    
$lang['label.direccion'] = 'Direccion';
    
$lang['label.logo'] = 'Logo';
    
$lang['label.url_portal'] = 'Url portal';
    
$lang['label.activo'] = 'Activo';
Como veis aún faltan cosas, pero bueno.. más o menos es bastante trabajo ahorrado, con un click se podrá tener el backend, evidentemente el código generado no es perfecto, pero poco a poco mejora, y la idea no es generar un código cerrado perfecto, si no un código que tras ser generado sea flexible y customizable,


Un saludo!
__________________
Gracias por el Karma :D

empleo ofertas de trabajo
  #21 (permalink)  
Antiguo 30/09/2011, 01:21
 
Fecha de Ingreso: julio-2008
Ubicación: Barcelona
Mensajes: 2.100
Antigüedad: 15 años, 8 meses
Puntos: 165
Respuesta: generador de modelos, controladores y vistas

Se me olvidaba, si alguien se anima con dos tablas relacionadas también tengo prevista esta funcionalidad, y en el add, me haría el desplegable con la relación :D

edito, los controladores tienen llamadas a views como succes etc que no irán así, tampoco se cargarán las vistas de esa manera en los controladores generados, el tema controladores esta un poco verde.

También el tema validaciones y config_form le queda retocar algo, como maxlenght pero es poca cosa
__________________
Gracias por el Karma :D

empleo ofertas de trabajo
  #22 (permalink)  
Antiguo 02/10/2011, 22:01
 
Fecha de Ingreso: febrero-2007
Mensajes: 33
Antigüedad: 17 años, 1 mes
Puntos: 0
Respuesta: generador de modelos, controladores y vistas

Excelente! Tienes publicado el generador en algún lado? Me gustaría probar y ver como funciona y si me podría servir para los proyectos que hago.


Saludos y muchas gracias!
  #23 (permalink)  
Antiguo 03/10/2011, 00:48
 
Fecha de Ingreso: julio-2008
Ubicación: Barcelona
Mensajes: 2.100
Antigüedad: 15 años, 8 meses
Puntos: 165
Respuesta: generador de modelos, controladores y vistas

Hola,

Muchas gracias! nadie respondía a este post... jaja no lo tengo subido ni acabado, mejora cada día, y cada vez es más configurable ( se pueden personalizar cada una de las variables, funciones, etc generadas ), en cuanto lo tenga listo lo subiré, estaría bien que hicieras peticiones con lo que os gustaría que generase, ahora he realizado cambios importantes,

Un saludo!
__________________
Gracias por el Karma :D

empleo ofertas de trabajo
  #24 (permalink)  
Antiguo 03/10/2011, 09:14
Avatar de Ronruby  
Fecha de Ingreso: julio-2008
Ubicación: 18°30'N, 69°59'W
Mensajes: 4.879
Antigüedad: 15 años, 8 meses
Puntos: 416
Respuesta: generador de modelos, controladores y vistas

Cita:
Iniciado por miktrv Ver Mensaje
Hola,

Muchas gracias! nadie respondía a este post... jaja no lo tengo subido ni acabado, mejora cada día, y cada vez es más configurable ( se pueden personalizar cada una de las variables, funciones, etc generadas ), en cuanto lo tenga listo lo subiré, estaría bien que hicieras peticiones con lo que os gustaría que generase, ahora he realizado cambios importantes,

Un saludo!
Hola miktrv,

Probare crear la tabla y configurar CI para verificar que tal ;)
Te dejo saber en un rato.
  #25 (permalink)  
Antiguo 03/10/2011, 10:18
 
Fecha de Ingreso: julio-2008
Ubicación: Barcelona
Mensajes: 2.100
Antigüedad: 15 años, 8 meses
Puntos: 165
Respuesta: generador de modelos, controladores y vistas

Si te lo paso de nuevo estará mejor, recuerda que tienes que tener HMVC instalado en CI.

Lo ideal sería pasarte un .zip con todos los ficheros.. porque son database, config, view, language, library, controller, model...

Un saludo!
__________________
Gracias por el Karma :D

empleo ofertas de trabajo
  #26 (permalink)  
Antiguo 03/10/2011, 12:13
Avatar de Ronruby  
Fecha de Ingreso: julio-2008
Ubicación: 18°30'N, 69°59'W
Mensajes: 4.879
Antigüedad: 15 años, 8 meses
Puntos: 416
Respuesta: generador de modelos, controladores y vistas

Ok, subelo a un servidor y pasame el link :)
  #27 (permalink)  
Antiguo 04/10/2011, 01:17
 
Fecha de Ingreso: julio-2008
Ubicación: Barcelona
Mensajes: 2.100
Antigüedad: 15 años, 8 meses
Puntos: 165
Respuesta: generador de modelos, controladores y vistas

Ok, lo subo y te paso el link,

Un saludo!
__________________
Gracias por el Karma :D

empleo ofertas de trabajo
  #28 (permalink)  
Antiguo 05/10/2011, 01:01
 
Fecha de Ingreso: julio-2008
Ubicación: Barcelona
Mensajes: 2.100
Antigüedad: 15 años, 8 meses
Puntos: 165
Respuesta: generador de modelos, controladores y vistas

Coloco el código generado:

Library:

Código PHP:
<?php

/*

    Description
    @author            miktrv
    @package           Aseguradoras

*/

class Aseguradoras_entity {

    private 
$id_aseguradora;
    public 
$aseguradora;
    public 
$direccion;
    public 
$logo;
    public 
$url_portal;
    public 
$activo;

    
/*
        @package    Aseguradoras

        @access     public
        @return     void
        @param      
    */

    
public function __construct($id_aseguradora FALSE) {
    
        if(
$id_aseguradora) {
            
$this->id_aseguradora $id_aseguradora;
            
$this->load_by_id_aseguradora();
        } else {
            
//set default values
            
$this->activo 1;
        }
    }

//----------------------------------------------------------------------------------------------


    /*
        @package    Aseguradoras

        @access     public
        @return     void
        @param      Integer
    */

    
public function set_id_aseguradora($id_aseguradora) {
    
        
$this->id_aseguradora $id_aseguradora;
    
    }

//----------------------------------------------------------------------------------------------


    /*
        @package    Aseguradoras

        @access     public
        @return     Integer
    */

    
public function get_id_aseguradora() {
    
        return 
$this->id_aseguradora;
    
    }

//----------------------------------------------------------------------------------------------


    /*
        @package    Aseguradoras

        @access     public
        @return     void
        @param      String
    */

    
public function set_aseguradora($aseguradora) {
    
        
$this->aseguradora $aseguradora;
    
    }

//----------------------------------------------------------------------------------------------


    /*
        @package    Aseguradoras

        @access     public
        @return     String
    */

    
public function get_aseguradora() {
    
        return 
$this->aseguradora;
    
    }

//----------------------------------------------------------------------------------------------


    /*
        @package    Aseguradoras

        @access     public
        @return     void
        @param      MEDIUMTEXT
    */

    
public function set_direccion($direccion) {
    
        
$this->direccion $direccion;
    
    }

//----------------------------------------------------------------------------------------------


    /*
        @package    Aseguradoras

        @access     public
        @return     MEDIUMTEXT
    */

    
public function get_direccion() {
    
        return 
$this->direccion;
    
    }

//----------------------------------------------------------------------------------------------


    /*
        @package    Aseguradoras

        @access     public
        @return     void
        @param      String
    */

    
public function set_logo($logo) {
    
        
$this->logo $logo;
    
    }

//----------------------------------------------------------------------------------------------


    /*
        @package    Aseguradoras

        @access     public
        @return     String
    */

    
public function get_logo() {
    
        return 
$this->logo;
    
    }

//----------------------------------------------------------------------------------------------


    /*
        @package    Aseguradoras

        @access     public
        @return     void
        @param      String
    */

    
public function set_url_portal($url_portal) {
    
        
$this->url_portal $url_portal;
    
    }

//----------------------------------------------------------------------------------------------


    /*
        @package    Aseguradoras

        @access     public
        @return     String
    */

    
public function get_url_portal() {
    
        return 
$this->url_portal;
    
    }

//----------------------------------------------------------------------------------------------


    /*
        @package    Aseguradoras

        @access     public
        @return     void
        @param      Boolean
    */

    
public function set_activo($activo 1) {
    
    if(
$activo) {
        
$activo 1;
    } else {
        
$activo 0;
    }
    
        
$this->activo $activo;
    
    }

//----------------------------------------------------------------------------------------------


    /*
        @package    Aseguradoras

        @access     public
        @return     Boolean
    */

    
public function get_activo() {
    
        return 
$this->activo;
    
    }

//----------------------------------------------------------------------------------------------


    /*
        @package    Aseguradoras

        @access     public
        @return     Aseguradoras
    */

    
public function load_by_id_aseguradora() {
    

        if(
$this->id_aseguradora) {

    
            
$sql '

            SELECT
                    ' 
TABLE_ASEGURADORAS_FIELD_ASEGURADORA ', 
                ' 
TABLE_ASEGURADORAS_FIELD_DIRECCION ', 
                ' 
TABLE_ASEGURADORAS_FIELD_LOGO ', 
                ' 
TABLE_ASEGURADORAS_FIELD_URL_PORTAL ', 
                ' 
TABLE_ASEGURADORAS_FIELD_ACTIVO '
            FROM ' 
TABLE_ASEGURADORAS '
            WHERE ' 
TABLE_ASEGURADORAS_FIELD_ID_ASEGURADORA ' = \'' $this->id_aseguradora '\'

            '
;
            
$query mysql_query($sql);
            
$row mysql_fetch_array($query);
            
$this->set_aseguradora($row[TABLE_ASEGURADORAS_FIELD_ASEGURADORA]);
            
$this->set_direccion($row[TABLE_ASEGURADORAS_FIELD_DIRECCION]);
            
$this->set_logo($row[TABLE_ASEGURADORAS_FIELD_LOGO]);
            
$this->set_url_portal($row[TABLE_ASEGURADORAS_FIELD_URL_PORTAL]);
            
$this->set_activo($row[TABLE_ASEGURADORAS_FIELD_ACTIVO]);

        }

    }

//----------------------------------------------------------------------------------------------


    /*
        @package    Aseguradoras

        @access     public
        @return     integer
    */

    
public function update_by_id_aseguradora() {
    
        
$out 0;
    
        if(
$this->id_aseguradora) {

    
            
$sql '

            UPDATE ' 
TABLE_ASEGURADORAS ' SET 
                    ' 
TABLE_ASEGURADORAS_FIELD_ASEGURADORA ' = \'' $this->aseguradora '\', 
                ' 
TABLE_ASEGURADORAS_FIELD_DIRECCION ' = \'' $this->direccion '\', 
                ' 
TABLE_ASEGURADORAS_FIELD_LOGO ' = \'' $this->logo '\', 
                ' 
TABLE_ASEGURADORAS_FIELD_URL_PORTAL ' = \'' $this->url_portal '\', 
                ' 
TABLE_ASEGURADORAS_FIELD_ACTIVO ' = \'' $this->activo '\'
            WHERE ' 
TABLE_ASEGURADORAS_FIELD_ID_ASEGURADORA ' = \'' $this->id_aseguradora '\'

            '
;
    
            
$query mysql_query($sql);
            
$out mysql_affected_rows();

        }

        return 
$out;

    }

//----------------------------------------------------------------------------------------------


    /*
        @package    Aseguradoras

        @access     public
        @return     boolean
    */

    
public function insert() {
    
        
$out FALSE;
    
        
$sql '

        INSERT INTO ' 
TABLE_ASEGURADORAS '
        (
            ' 
TABLE_ASEGURADORAS_FIELD_ASEGURADORA ', 
            ' 
TABLE_ASEGURADORAS_FIELD_DIRECCION ', 
            ' 
TABLE_ASEGURADORAS_FIELD_LOGO ', 
            ' 
TABLE_ASEGURADORAS_FIELD_URL_PORTAL ', 
            ' 
TABLE_ASEGURADORAS_FIELD_ACTIVO '

        )
        VALUES
        (
            \'' 
$this->aseguradora '\', 
            \'' 
$this->direccion '\', 
            \'' 
$this->logo '\', 
            \'' 
$this->url_portal '\', 
            \'' 
$this->activo '\'

        )
        ;
        '
;
    
        if(
mysql_query($sql) and mysql_affected_rows() == 1) {
            
$out TRUE;
        }
        
$this->id_aseguradora mysql_insert_id();
            
        return 
$out;
    
    }

//----------------------------------------------------------------------------------------------


    /*
        Save the data in database, check if register exists for create or update

        @package    Aseguradoras

        @access     public
        @return     boolean
    */

    
public function save() {
    
        if(
$this->get_id_aseguradora()) {
            return 
$this->update();
        } else {
            return 
$this->insert();
        }
    
    }

//----------------------------------------------------------------------------------------------


    /*
        Save data when object deleted in memory! :D

        @package    Aseguradoras

        @access     public
        @return     void
    */

    /*
    public function __destruct() {
    
            $this->save();
    
    }
    */

//----------------------------------------------------------------------------------------------

}
__________________
Gracias por el Karma :D

empleo ofertas de trabajo
  #29 (permalink)  
Antiguo 05/10/2011, 01:03
 
Fecha de Ingreso: julio-2008
Ubicación: Barcelona
Mensajes: 2.100
Antigüedad: 15 años, 8 meses
Puntos: 165
Respuesta: generador de modelos, controladores y vistas

Model
Código PHP:
<?php

class Aseguradoras_model extends CI_Model {


    
/*
        @package    Aseguradoras

        @access     public
        @return     void
    */

    
public function __construct() {
    
        
parent::__construct();
        
    }


    
/*
        @package    Aseguradoras

        @access     public
        @return     array
        @param      String
    */

    
public function get_all($sql_extra '') {
    
        
$out = array();
    
        
$sql '
        
            SELECT
                ' 
TABLE_ASEGURADORAS_FIELD_ID_ASEGURADORA ', 
            ' 
TABLE_ASEGURADORAS_FIELD_ASEGURADORA ', 
            ' 
TABLE_ASEGURADORAS_FIELD_DIRECCION ', 
            ' 
TABLE_ASEGURADORAS_FIELD_LOGO ', 
            ' 
TABLE_ASEGURADORAS_FIELD_URL_PORTAL ', 
            ' 
TABLE_ASEGURADORAS_FIELD_ACTIVO '

            FROM ' 
TABLE_ASEGURADORAS '

        '
;
        
        if(!empty(
$sql_extra)) {
            
$sql .= ' ' $sql_extra;
        }
    
        
$query mysql_query($sql);

        while(
$row mysql_fetch_array($query)) {

            
$temp_object = new Aseguradoras_entity();
            
$temp_object->set_id_aseguradora($row[TABLE_ASEGURADORAS_FIELD_ID_ASEGURADORA]);
            
$temp_object->set_aseguradora($row[TABLE_ASEGURADORAS_FIELD_ASEGURADORA]);
            
$temp_object->set_direccion($row[TABLE_ASEGURADORAS_FIELD_DIRECCION]);
            
$temp_object->set_logo($row[TABLE_ASEGURADORAS_FIELD_LOGO]);
            
$temp_object->set_url_portal($row[TABLE_ASEGURADORAS_FIELD_URL_PORTAL]);
            
$temp_object->set_activo($row[TABLE_ASEGURADORAS_FIELD_ACTIVO]);

            
//add object to array
            
array_push($out$temp_object);

        }

        return 
$out;

    }

    
/*
        @package    Aseguradoras

        @access     public
        @return     array
        @param      Integer
        @param      Integer
        @param      String
    */

    
public function get_all_extends($limit_left FALSE$limit_right FALSE$condition '') {
    
        
$sql_extra '';
    
        if(!empty(
$condition)) {
            
$sql_extra .= ' WHERE ' $condition;
        }
      
        if(
is_numeric($limit_left)) {
            
$sql_extra .= ' LIMIT ' $limit_left;
        }

        if(
is_numeric($limit_right) and is_numeric($limit_left)) {
            
$sql_extra .= ', ' $limit_right;
        }

    
        return 
$this->get_all($sql_extra);

    }

    
/*
        @package    Aseguradoras

        @access     public
        @return     integer
        @param      String
    */

    
public function get_count($condition '') {
    
        
$out 0;

        
$sql 
        
'   
            SELECT 
            COUNT(' 
TABLE_ASEGURADORAS_FIELD_ID_ASEGURADORA ') AS count 
            FROM ' 
TABLE_ASEGURADORAS 

        '
;

        if(!empty(
$condition)) {
            
$sql .= ' WHERE ' $condition;
        }

        
$query mysql_query($sql);

        
$row mysql_fetch_array($query);

        
$out $row['count'];

        return 
$out;
            
    }

    
/*
        @package    Aseguradoras

        @access     public
        @return     boolean
        @param      Integer
    */

    
public function exists_by_id_aseguradora($id_aseguradora FALSE) {
    
        
$out 0;

        if(
$id_aseguradora) {

            
$sql 
            
'   
                SELECT 
                COUNT(' 
TABLE_ASEGURADORAS_FIELD_ID_ASEGURADORA ') AS count 
                FROM ' 
TABLE_ASEGURADORAS 
                WHERE ' 
TABLE_ASEGURADORAS_FIELD_ID_ASEGURADORA ' = \'' $id_aseguradora '\'
            '
;

            
$query mysql_query($sql);

            
$row mysql_fetch_array($query);

            if(
$row['count'] == 1) {

                
$out TRUE;

            }

        }

        return 
$out;
            
    }

    
/*
        @package    Aseguradoras

        @access     public
        @return     Aseguradoras
        @param      Integer
    */

    
public function get_by_id_aseguradora($id_aseguradora FALSE) {
    
        
$Aseguradoras_entity = new Aseguradoras_entity();

        if(
$id_aseguradora) {

            
$Aseguradoras_entity->set_id_aseguradora($id_aseguradora);

            
$sql '

            SELECT
                    ' 
TABLE_ASEGURADORAS_FIELD_ASEGURADORA ', 
                ' 
TABLE_ASEGURADORAS_FIELD_DIRECCION ', 
                ' 
TABLE_ASEGURADORAS_FIELD_LOGO ', 
                ' 
TABLE_ASEGURADORAS_FIELD_URL_PORTAL ', 
                ' 
TABLE_ASEGURADORAS_FIELD_ACTIVO '
            FROM ' 
TABLE_ASEGURADORAS '
            WHERE ' 
TABLE_ASEGURADORAS_FIELD_ID_ASEGURADORA ' = \'' $id_aseguradora '\'

            '
;
    
            
$query mysql_query($sql);
            
$row mysql_fetch_array($query);
            
$Aseguradoras_entity->set_aseguradora($row[TABLE_ASEGURADORAS_FIELD_ASEGURADORA]);
            
$Aseguradoras_entity->set_direccion($row[TABLE_ASEGURADORAS_FIELD_DIRECCION]);
            
$Aseguradoras_entity->set_logo($row[TABLE_ASEGURADORAS_FIELD_LOGO]);
            
$Aseguradoras_entity->set_url_portal($row[TABLE_ASEGURADORAS_FIELD_URL_PORTAL]);
            
$Aseguradoras_entity->set_activo($row[TABLE_ASEGURADORAS_FIELD_ACTIVO]);

        }

        return 
$Aseguradoras_entity;

    }

    
/*
        @package    Aseguradoras

        @access     public
        @return     integer
        @param      Integer
        @param      String
        @param      MEDIUMTEXT
        @param      String
        @param      String
        @param      Boolean
    */

    
public function update_by_id_aseguradora($id_aseguradora$aseguradora$direccion$logo$url_portal$activo) {
    
        
$out 0;
    
        if(
$id_aseguradora) {

    
            
$sql '

            UPDATE ' 
TABLE_ASEGURADORAS ' SET 
                    ' 
TABLE_ASEGURADORAS_FIELD_ASEGURADORA ' = \'' $aseguradora '\', 
                ' 
TABLE_ASEGURADORAS_FIELD_DIRECCION ' = \'' $direccion '\', 
                ' 
TABLE_ASEGURADORAS_FIELD_LOGO ' = \'' $logo '\', 
                ' 
TABLE_ASEGURADORAS_FIELD_URL_PORTAL ' = \'' $url_portal '\', 
                ' 
TABLE_ASEGURADORAS_FIELD_ACTIVO ' = \'' $activo '\'
            WHERE ' 
TABLE_ASEGURADORAS_FIELD_ID_ASEGURADORA ' = \'' $id_aseguradora '\'

            '
;
    
            
$query mysql_query($sql);
            
$out mysql_affected_rows();

        }

        return 
$out;

    }

//----------------------------------------------------------------------------------------------


    /*
        @package    Aseguradoras

        @access     public
        @return     integer
        @param      Integer
    */

    
public function delete_by_id_aseguradora($id_aseguradora FALSE) {
    
        
$out 0;

        if(
$id_aseguradora) {

            
$sql 
            
'   
                DELETE FROM ' 
TABLE_ASEGURADORAS 
                WHERE ' 
TABLE_ASEGURADORAS_FIELD_ID_ASEGURADORA ' = \'' $id_aseguradora '\'

            '
;

            
$query mysql_query($sql);

            
$out mysql_affected_rows();

        }

        return 
$out;
            
    }

//----------------------------------------------------------------------------------------------

    /*
        @package    Aseguradoras

        @access     public
        @return     boolean
        @param      String
        @param      MEDIUMTEXT
        @param      String
        @param      String
        @param      Boolean
    */

    
public function insert($aseguradora ''$direccion ''$logo ''$url_portal ''$activo 1) {
    
        
$out FALSE;
    
            if(
$activo) {
                
$activo 1;
            } else {
                
$activo 0;
            }

            
        
$sql '

        INSERT INTO ' 
TABLE_ASEGURADORAS '
        (
            ' 
TABLE_ASEGURADORAS_FIELD_ASEGURADORA ', 
            ' 
TABLE_ASEGURADORAS_FIELD_DIRECCION ', 
            ' 
TABLE_ASEGURADORAS_FIELD_LOGO ', 
            ' 
TABLE_ASEGURADORAS_FIELD_URL_PORTAL ', 
            ' 
TABLE_ASEGURADORAS_FIELD_ACTIVO '

        )
        VALUES
        (
            \'' 
$aseguradora '\', 
            \'' 
$direccion '\', 
            \'' 
$logo '\', 
            \'' 
$url_portal '\', 
            \'' 
$activo '\'

        )
        ;
        '
;
    
        if(
mysql_query($sql) and mysql_affected_rows() == 1) {
            
$out TRUE;
        }
                    
        return 
$out;
    
    }

//----------------------------------------------------------------------------------------------


    /*
        @package    Aseguradoras

        @access     public
        @return     boolean
        @param      String
        @param      MEDIUMTEXT
        @param      String
        @param      String
        @param      Boolean
    */

    
public function insert_extends($aseguradora ''$direccion ''$logo ''$url_portal ''$activo 1) {
        return 
$this->insert($aseguradora,$direccion,$logo,$url_portal,$activo);
    }

//----------------------------------------------------------------------------------------------

}
__________________
Gracias por el Karma :D

empleo ofertas de trabajo
  #30 (permalink)  
Antiguo 05/10/2011, 01:04
 
Fecha de Ingreso: julio-2008
Ubicación: Barcelona
Mensajes: 2.100
Antigüedad: 15 años, 8 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

Etiquetas: controladores, generador, modelos, php, vistas
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 03:49.