我正在敲打键盘试图找出一种方法来使用查询字符串和分页,每一件事情都可以正常工作,直到FIRST页面链接出现.
所有其他链接都将查询字符串附加到其末尾,但是第一页链接错过了查询字符串
其他页面的链接:
http://localhost/index.php/search/index/9?q=some_Data_From_Form
FIRST页面链接显示我在$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的文本框.
我在stackoverflow上偶然发现了几个答案/示例,这就是我写的:
分页配置文件有
$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
}
}
}
S.O.S!伙计们,请帮帮我