CodeIgniter Forums
Two drop down with one view with diferent models? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Two drop down with one view with diferent models? (/thread-9264.html)



Two drop down with one view with diferent models? - El Forum - 06-18-2008

[eluser]Asinox[/eluser]
Hi, my situation is the next:

My module for create Categories is fine, but my module for create Subcategories is wrong.

I have one controller for categories and another for subcategories, and one model for categories and another for subcategories.

In my module for create subcategories i have one drop down for select the category father and another one text input for create the subcategory, but the drop down for category dont bring data Sad and i cant create subcategories because i need categories first.

where is my problem? im lost.

i need one model for this or more?

i dont know

my subcategories model
Code:
/*var $subcategoria    = '';
        var $publicar        = '';
        var $categoria        = '';*/
        
        function Subcategorias_model(){
            parent::Model();
            //$this->load->database();
        }
        
        function listar(){  //HERE IM GETTING SUBCATEGORIES
            $this->load->database();
            $data['titulo_site'] = "Paso a Paso Online | Bienvenido";
            $query = $this->db->get('subcategories');
            return $query->result();
        }
        function listar_categorias(){   //HERE I WANT GET CATEGORIES
            $this->load->database();
            $query2 = $this->db->get('categories');
            return $query2->result();
        }
        function agregar(){
            $this->input->post('subcategoria');
            $this->input->post('publicar');            
            $this->input->post('categoria');            
            $query = $this->db->insert('subcategories',$this);
        }
        
        /*function actualizar(){
            $this->input->post('subcategoria');
            $this->input->post('publicar');            
            $this->input->post('categoria');            
            $query = $this->db->update('subcategories',$this,array('id',$_POST['id']));        
        }
        
        function borrar(){
            //faltan cosas
        }*/
    }



controller
Code:
class Administracion extends Controller{
        function Administracion(){
            parent::Controller();
            $this->load->helper('form');
            $this->load->helper('url');
            $this->load->library('validation');
            
        }
        
        function index(){
            $data['titulo_site'] = "Paso a Paso Online | Bienvenido";
            $rules['categoria']    = "required";
            $this->validation->set_rules($rules);

            
            if ($this->validation->run() == FALSE){
                $this->load->view('administracion/categorias_view');
            }else{
                $this->load->view('administracion/formsuccess');
            }
        }
        
        function categorias(){  //HERE FUNCTION FOR GET CATEGORIES IN CATEGORIES VIEW..IS FINE
            $data['titulo_site'] = "Paso a Paso Online | Panel de Administracion";
            $this->load->model('administracion/categorias_model');
            $data['query'] = $this->categorias_model->get_categorias();
            $this->load->view('administracion/categorias_view',$data);            
        }
        
        function listar_categorias_padres(){ //HERE I WANT GET GET CATEGORIES FATHER IN SUBCATEGORIES VIEW..
            $this->load->model('administracion/categorias_model');
            $data2['query2'] = $this->categorias_model->get_categorias();
            $this->load->view('administracion/subcategorias_view',$data2);
        }
        function subcategorias(){ // HERE IM GETTING ALL SUBCATEGORIES...IS FINE
            $data['titulo_site'] = "Paso a Paso Online | Panel de Administracion";
            $this->load->model('administracion/subcategorias_model');
            $data['query'] = $this->subcategorias_model->listar();
            $this->load->view('administracion/subcategorias_view',$data);                    
        }
    }

View subcategories
Code:
//here im displaying all subcategories...is fine (i test with direct data in table)

foreach($query as $row):
    echo "<tr><td>".$row->id."</td><td>".$row->subcategoria."</td><td>&lt;input type=\"checkbox\" name=\"action\" value=".$row-&gt;id."></a></td></tr>";
endforeach;

// here the select NO FINE with categories
<span>Categoria</span>
<select name="categoria">
<option selected="selected" value="0">Seleccione una Categoria</option>
&lt;?php foreach($query2 as $row2):
    echo "<option value=\"".$row2->id."\">".$row2->categoria."</option>";
endforeach; ?&gt;
</select><br />


please im new with CI and OOP

Thanks