简体   繁体   English

Codeigniter分页和搜索问题

[英]Issue with Codeigniter Pagination And Search

I am trying to give facility of pagination and search keyword in one report with Code-igniter Framework. 我试图在一个报告中使用Code-igniter Framework提供分页功能和搜索关键字

Below is the Controller code for that Purpose: 以下是该目的的Controller代码:

$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);

Getting Below link in pagination links which is not working: 在分页链接中获取以下链接:

http://Host/project/reports/mysearch_search/?start_date=2014-01-23&end_date=2014-01-23&keyword=/2

Url i am expecting in pagination links is like: 我希望在分页链接中的网址如下:

http://Host/project/reports/mysearch_search/2?start_date=2014-01-23&end_date=2014-01-23&keyword=

How can i will Get right Url for searching Purpose? 我怎样才能获得正确的Url搜索目的?

Here is nice example from codeignter itself. 这是codeignter本身的一个很好的例子。 Codeigniter Pagination check this. Codeigniter分页检查这个。

By default codeigniter is expecting the pagination url like this. 默认情况下,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);  

and if you need this kind of url then you have to change the 如果你需要这种网址,那么你必须改变

http://example.com/index.php?c=test&m=page&per_page=20

then you have to change to set this on config file 然后你必须改变配置文件上的这个

$config['enable_query_strings'] set to TRUE $ config ['enable_query_strings']设置为TRUE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM