2016-11-26 60 views
1

我有一個程序,我有搜索代碼。當我搜索它時會顯示一個搜索結果的頁面。該頁面將顯示一些可點擊的內容。當我點擊該內容時,它會向我顯示產品的細節。在此詳細信息頁面中,當我在瀏覽器中單擊時,它應回到搜索結果頁面,但我在此處獲得文檔過期。當我重新加載文檔過期的頁面時,它會再次顯示搜索結果。我正在使用codeigniter。我嘗試了一些我發現的代碼,但它仍然不起作用。這是我的問題。請幫幫我。謝謝。文件已過期在Codeigniter中搜索後按瀏覽器

控制器

public function search_bar($keyWordRestoran=NULL, $page=NULL, $orderBy=NULL) 
     { 
      if($this->session->userdata('logged_in')) 
      { 
       $session_data = $this->session->userdata('logged_in'); 
       $data['nama'] = $session_data['nama']; 
       $data['id'] = $session_data['id_user']; 
       $data['tipeUser'] = $session_data['tipe_user']; 

      } 
      else{ 
       $data['nama'] = ""; 
       $data['id'] = "0"; 
       $data['tipeUser']=""; 
      } 
      $data['url_image'] = $this->imageUrl; 
      $keyWordRestoran_ip = $this->input->post('input-keyword'); 
      if($keyWordRestoran_ip=="") 
      { 
       $session_data = $this->session->userdata('keyword_resto'); 
       $keyWordRestoran = $session_data['keyword_resto']; 
      } 
      else{ 
       $sess_array2 = array(); 
       $sess_array2 = array(
        'keyword_resto' => $keyWordRestoran_ip 
        ); 
       $this->session->set_userdata('keyword_resto', $sess_array2); 
       $session_data = $this->session->userdata('keyword_resto'); 
       $keyWordRestoran = $session_data['keyword_resto']; 
      } 

      $data['kunci_cari'] = $keyWordRestoran; 

      $config['base_url'] = base_url().'/home_controller/search_bar/'.$keyWordRestoran; 

      $data['jmlh_rows'] = $this->restoran->GetRestoran_search($keyWordRestoran); 

      $total_row = $data['jmlh_rows']->num_rows(); 

      $config["total_rows"] = $total_row; 
      $config["per_page"] = 8; 
      $config['cur_tag_open'] = '&nbsp;<a class="current">'; 
      $config['cur_tag_close'] = '</a>'; 
      $config['next_link'] = 'Next'; 
      $config['prev_link'] = 'Previous'; 

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

      $str_links = $this->pagination->create_links(); 
      $data["links"] = explode('&nbsp;',$str_links); 
      $data["dataRestoran"] = $this->restoran->GetRestoranPerPage_search($config["per_page"], $keyWordRestoran, $page, $orderBy); 
      $data['url_image'] = $this->imageUrl; 
      $data['data_kategori'] = $this->jenismakanan->Getjenismakanan(); 
      $this->load->view('food-type_search', $data); 
     } 

搜索查看

<div class="header-bottom"> 
    <div class="col-xs-1"> 
     <button class="toggle-button"></button> 
    </div> 
    <div class="col-xs-11"> 
    <?php echo form_open('home_controller/search_bar');?> 
    <div class="search"> 
    <form method="GET"> 
     <input type="text" id= "input-keyword" name="input-keyword" placeholder="Search ..." value="<?php echo set_value('input-keyword')?>" > 
     <input type="submit" value=""> 
    </form><?php echo form_close(); ?> 
    </div> 
    </div> 
<div class="clearfix"> </div> 

+1

我的事情你正在使用POST方法搜索表單獲取表單值這個代碼 -

<div class="header-bottom"> <div class="col-xs-1"> <button class="toggle-button"></button> </div> <div class="col-xs-11"> <?php echo form_open('home_controller/search_bar',array('method' => 'get'));?> <div class="search"> <input type="text" id= "input-keyword" name="input-keyword" placeholder="Search ..." value="<?php echo set_value('input-keyword')?>" > <input type="submit" value=""> </div> <?php echo form_close(); ?> </div> <div class="clearfix"> </div> 

。嘗試使用get方法。 –

+0

如何使用輸入獲取?我試圖像這樣使用它 '$ keyWordRestoran_ip = $ this-> input-> get('input-keyword'); ' 什麼都沒有發生@PrakashSaini –

+0

請在您的問題中只包含_relevant_代碼。在這種情況下,搜索表單,可能連接到搜索表單的任何JS以及處理實際搜索的結果代碼。 –

回答

2

您已包括形狀兩次。一種形式是使用<?php echo form_open('home_controller/search_bar');?>創建的,另一種形式是html中的靜態形式。所以需要刪除靜態html表單並且for_open可以。在form_open中,你需要指定方法get。在這裏,我已經更新在你search_bar功能控制器現在用get方法,而不是像後作爲

$keyWordRestoran_ip = $this->input->get('input-keyword'); 
+0

它的工作。謝謝 –