2011-05-21 40 views
8

我敲我的頭在鍵盤上試圖找出一種方法來使用分頁查詢字符串每件事情都很好,直到FIRST頁面鏈接出現。使用分頁查詢字符串的方法設置得到codeigniter

所有其他鏈接都附加到其最終的查詢字符串,但First頁面鏈接misses the query string

鏈接其他網頁:

http://localhost/index.php/search/index/9?q=some_Data_From_Form 

第一頁的鏈接顯示,我已經設置鏈接所述$config['base_url'] 變量:

http://localhost/index.php/search/index/ 

搜索表單:

$attributes=array('id'=>'search','class'=>'clearfix','method'=>'get'); 
echo form_open(base_url().'index.php/search/index',$attributes); 

它有一個名稱設置爲q的文本框。

我偶然發現了計算器上的幾個答案/例子,這是我寫的:

分頁配置文件有

$config['per_page'] = '1'; 
$config['uri_segment'] = '3'; 

和其他類似num_tag_open

控制器類:

class Search extends CI_Controller { 
    public function Search(){ 
     parent::__construct(); 
     $this->load->helper('url'); 
     $this->load->helper('form'); 
     $this->load->library('input'); 
     $this->load->model('blog_model'); 
     $this->load->library('pagination'); 
     $this->config->load('pagination'); //other pagination related config variables 
    } 

    public function index($page=0){ 
     $q = trim($this->input->get('q')); 
     if(strlen($q)>0){ 
      //validate input and show data 
      $config['enable_query_strings']=TRUE; 
      $getData = array('q'=>$q); 
      $config['base_url'] = 'http://localhost/index.php/search/index/'; 
      $config['suffix'] = '?'.http_build_query($getData,'',"&"); 

      $data['rows'] = $this->blog_model->getBySearch($q,$this->config->item('per_page'),$page); 
      if(empty($data['rows'])){ 
       //no results found    

      }else{ 
       //match found 
       $config['total_rows'] = $this->blog_model->getBySearchCount($q); 
       $this->pagination->initialize($config); 
       $link->linkBar = $this->pagination->create_links(); 
       $this->load->view('myview',array($data,$link)); 
      } 
     }else if(strlen($q)==0){ 
      //warn user for the missing query and show a searchbox 

     } 
    } 
} 

SOS!夥計們,請幫助我

+0

+1對於你的頭和鍵盤:D – 2013-05-06 02:58:12

回答

10

我不敢相信這一點,我花了幾個小時在網上尋找解決方案! 它總是和我在一起。我應該在我發佈這個問題之前打開分頁庫並查看它的內容。只有一行和問題解決了。
我在索引方法中添加了以下行。
$config['first_url'] = '/index.php/search/index/?q='.$q;

+0

謝謝你的帖子真的有用。 – 2017-06-02 08:28:15