我敲我的頭在鍵盤上試圖找出一種方法來使用分頁查詢字符串每件事情都很好,直到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!夥計們,請幫助我
+1對於你的頭和鍵盤:D – 2013-05-06 02:58:12