Ver Mensaje Individual
  #3 (permalink)  
Antiguo 08/08/2012, 09:34
rpichinu
 
Fecha de Ingreso: noviembre-2010
Mensajes: 208
Antigüedad: 13 años, 5 meses
Puntos: 3
Respuesta: Explicar trozo de Codigo OOP PHP

no solo queria que me explicaran el trozo de codigo, pero ya lo entendi, otra duda necesito crear un combobox dinamico.

tengo:

Código PHP:
Ver original
  1. $region_code      = $this->cv_model->get_userdata('region', $data['user_id']);
  2.   $user_array         = $this->cv_model->get_data('users', '*', 'id', $data['user_id']);
  3.                    
  4.             foreach($user_array[0] as $user=>$v){
  5.                         $data['u'.$user]    = $v;
  6.                     }
  7.    $data['uregion_code']    = $data['uregion'];
  8.    $data['regions_select']  = $this->cv_model->fill_dropdown('regiones', 'codigo,nombre');
  9.    $region         = $this->cv_model->get_data('regiones', 'nombre', 'codigo', $data['uregion_code']);
  10.                     if($region){
  11.                         $data['uregion']     = $region[0];
  12.                     }

y el modelo es este:

Código PHP:
Ver original
  1. function get_data($table, $what = NULL, $where = NULL, $identifier = NULL){
  2.        
  3.         $data='';
  4.         if($what && $what != '*'){    
  5.             $this->db->select($what);
  6.             if($where)
  7.             $this->db->where($where, $identifier);
  8.             $query = $this->db->get($table);
  9.             foreach ($query->result_array() as $tablerow) {
  10.                               $data[] = $tablerow[$what];
  11.             }
  12.        
  13.       } else{
  14.             if($where)
  15.                 $this->db->where($where, $identifier);
  16.             if($orderby)
  17.                 $this->db->order_by($orderby, $ordertype);
  18.             $query = $this->db->get($table);
  19.             $data = $query->result_array();
  20.         }
  21.         return $data;
  22.     }
  23.    
  24.     function get_userdata($what, $user_id){
  25.        
  26.         $this->db->select($what);
  27.         $this->db->where('id', $user_id);
  28.         $query = $this->db->get('users');
  29.         $user = '';
  30.         foreach ($query->result_array() as $tablerow) {
  31.             $user = $tablerow[$what];
  32.         }
  33.         return $user;
  34.     }
  35.    
  36.     function fill_dropdown($table, $data, $where=NULL){
  37.        
  38.         $this->db->select($data);
  39.    
  40.     if($where)
  41.         $this->db->where('padre',$where);
  42.         $query = $this->db->get($table);
  43.         $ddmenu = array();
  44.         $ddmenu[''] = 'Seleccione';
  45.         $fields = explode(',', $data);
  46.         foreach ($query->result_array() as $tablerow) {
  47.             $index = $tablerow[$fields[0]];
  48.             $source = $tablerow[$fields[1]];
  49.             $ddmenu[$index] = $source;
  50.         }
  51.         return $ddmenu;
  52.     }
para crear otro select se que tengo que utilizar jquery y ajax pero bastara con esas funciones del modelo, por ejemplo con function fill_dropdown($table, $data, $where=NULL)?

que me dices gator?