CodeIgniter Forums

Full Version: [need help]how to call the dropdown if there is more than a model-view-controller?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]myrna[/eluser]
I'm making a search function for website online library.

I've made a model-view-controller for each search books, magazines, journals, and cd. (There are four model-view-controller for each category)

How do I make each model-view-controller for it so I can call via the dropdown? so that when I input the title and then choose the category that I want in the dropdown, the functionality can perform a search according to categories that have been selected in the dropdown.

I attach a model-view-controller to a book, due to a different category just adjust it.

Model
Code:
<?php
    class PencarianModel extends Model
    {    
        function PencarianModel()
        {
            parent::Model();
        }    
        
        /* Menampilkan Hasil Pencarian */
        function SearchResult($perPage,$uri,$judul)
        {
             $this->db->select('mp.judul, mp.pengarang,, k.kategori, mp.status_pustaka, p.nama_penerbit')
                     ->from('tbl_master_properti mp')
                     ->join('tbl_penerbit p', 'mp.id_penerbit=p.id_penerbit')
                     ->join('tbl_kategori k', 'k.id_kategori=mp.id_kategori');
      
            if(!empty($judul)) {
                $this->db->like('judul',$judul);
            }
            $this->db->order_by('id_master_properti','asc');
            $getData = $this->db->get('', $perPage, $uri);
            
            if($getData->num_rows() > 0)
                return $getData->result_array();
            else
                return null;
        }
    }
?>

view
Code:
<body>
<div class="clear"></div>
<div id="content_box" class="grid_24 box">
<caption>Masukkan judul yang akan anda cari</caption>
&lt;form id="form_pencarian" name="form_pencarian" method="post" action="&lt;?=base_url();?&gt;/search/"&gt;
  &lt;input name="judul" type="text" id="judul" size="30" maxlength="255" class="inputbox" value="&lt;?=$judul;?&gt;"/&gt;&nbsp;&nbsp;
  &lt;input name="submit" type="submit" id="submit" value="Cari" class="button"/&gt;
  <select>
<option>- - -Pilih Kategori- - -</option>
  <option>Buku</option>
  <option>CD</option>
  <option>Tugas Akhir</option>
  <option>Jurnal</option>
</select>

&lt;/form&gt;
<hr />
   <legend><caption>Hasil Pencarian</caption></legend>
   <table width="100%" border="1">
  <col align="left" />
  <col align="left" />
  <col align="right" />
  
  <tr>
    <th>Judul</th>
    <th>Pengarang</th>
    <th>Kategori Buku</th>
    <th>Penerbit</th>
    <th>Status (ada/tidak di perpustakaan)</th>
  </tr>
  <tr>
  <td>
       &lt;?php

    //ListBuku Hasil Pencarian
    
    if(count($ListBuku) > 0) {
        foreach($ListBuku as $row)
        {
                echo "<tr>
                        <td width=100 align=\"left\" valign=\"middle\">&nbsp;</td>
                        <td width=500>
                        <br>Judul :</br>
                        <span> ".$row['judul']."</span>
                        <br>Pengarang :</br>
                        <span>". $row['pengarang'] ."</span>
                        <br>Kategori Buku :</br>
                        <span>". $row['kategori'] ."</span>
                        <br>Penerbit :</br>
                        <span>". $row['nama_penerbit'] ."</span>
                        <br>Status buku :</br>
                        <span>". $row['status_pustaka'] ."</span>
                        </td>
                </tr>";
                    }
        echo $this->pagination->create_links();
    } else {
        echo "<div><strong>Hasil pencarian tidak ditemukan.</strong></div>";
    }
?&gt;
  
  </tr></td>

</table>


</div>
<div class="clear"></div>
&lt;/body&gt;
&lt;/html&gt;

controller
Code:
&lt;?php
    class Search extends Controller
    {    
        function Search()
        {
            parent::Controller();    
            $this->load->library('pagination');
        }
        
        function index()
        {
            if(isset($_POST['submit']))
            {
                $data['judul'] = $this->input->post('judul');
                
                //set session user data untuk pencarian, untuk paging pencarian
                $this->session->set_userdata('sess_judul', $data['judul']);
            } else {
                $data['judul'] = $this->session->userdata('sess_judul');
            }
            
            $this->db->like('judul', $data['judul']);
            $this->db->from('tbl_master_properti');
            
            //Pagination init
            $pagination['base_url']     = base_url().'index.php/ulang37/index/page/';
            $pagination['total_rows']     = $this->db->count_all_results();
            $pagination['full_tag_open'] = "<p><div class=\"pagination\">";
            $pagination['full_tag_close'] = "</div></p>";
            $pagination['cur_tag_open'] = "<span class=\"current\">";
            $pagination['cur_tag_close'] = "</span>";
            $pagination['num_tag_open'] = "<span class=\"disabled\">";
            $pagination['num_tag_close'] = "</span>";
            $pagination['per_page']     = "5";
            $pagination['uri_segment'] = 4;
            $pagination['num_links']     = 4;
            
            $this->pagination->initialize($pagination);
            
            $data['ListBuku'] = $this->pencarianmodel->SearchResult($pagination['per_page'],$this->uri->segment(4,0),$data['judul']);
            $data['current'] = 'search';
            $data['content'] = 'pencarian';
            $this->load->vars($data);
            $this->load->view('container', $data);
        }
    }
?&gt;

El Forum

[eluser]Ivar89[/eluser]
I'm not THAT skilled yet, but isen't it better to maken one model, one controller and one view?
Each category has his own ID so you can simply ask which ID(categorie) and the view will load that ID(categorie)