我正在尝试使用Code-igniter Framework在一个报告中提供分页和搜索关键字的功能。
以下是该目的的控制器代码:
$queryString="?start_date=".$values['start_date']."&end_date=".$values['start_date']."&keyword=".$values['keyword']."";
if($this->uri->segment(3)){
$offset=$this->uri->segment(3);
$config['base_url'] = base_url()."reports/mysearch_search/".$offset.$queryString;
}else{
$config['base_url'] = base_url()."reports/mysearch_search/".$queryString;
}
$query = $this->db->query("SELECT * FROM (`dlrReport`) WHERE LEFT(`res_submit_date`,10) >= '".$values['start_date']."' AND LEFT(`res_submit_date`,10) <= '".$values['end_date']."' AND (number LIKE '%".$values['keyword']."%' OR source LIKE '%".$values['keyword']."%')");
$config['total_rows']=$query->num_rows();
$config['per_page'] = 2;
$this->pagination->initialize($config);
$where = array('LEFT(res_submit_date,10) >=' => $values['start_date'],'LEFT(res_submit_date,10) <=' =>$values['end_date']);
$this->db->where($where);
$this->db->where("(number LIKE '%".$values['keyword']."%' OR source LIKE '%".$values['keyword']."%')");
$res = $this->db->get('dlrReport', $config['per_page'], $this->uri->segment(3));
$dlr['details']= $res->result();
$dlr['start_date']=$values['start_date'];
$dlr['end_date']=$values['end_date'];
$dlr['keyword']=$values['keyword'];
$this->load->view('mysearch',$dlr);
在分页链接中获取以下链接:
http://Host/project/reports/mysearch_search/?start_date=2014-01-23&end_date=2014-01-23&keyword=/2
我希望在分页链接中使用的网址如下:
http://Host/project/reports/mysearch_search/2?start_date=2014-01-23&end_date=2014-01-23&keyword=
我如何才能获得正确的网址搜索目的?
答案 0 :(得分:1)
这是codeignter本身的一个很好的例子。 Codeigniter Pagination检查一下。
默认情况下,codeigniter会像这样期待分页URL。
http://localhost/project/reports/mysearch_search/2014-01-23/2014-01-23/2
$start_date =$this->uri->segment(5);
$end_date = $this->uri->segment(6);
$keyword = $this->uri->segment(7);
如果您需要这种网址,则需要更改
http://example.com/index.php?c=test&m=page&per_page=20
然后你必须改为在配置文件
上设置它$ config ['enable_query_strings']设置为TRUE