avinmo 发表于 2009-8-28 09:56:10

CI设置 'enable_query_strings'为 TRUE后的分页使用Pathinfo的问题

前几天我发了篇使用Jquery的Ajax+CI来实现自动提示完成功能,因为需要用到的一个JQuery插件所需要使用query_string方式的URL来传递数据。所以我把CI的config文件里设置$config['enable_query_strings'] = TRUE;但修改后,原来用CI写的分页页面出了问题,原因是CI设置$config['enable_query_strings'] = TRUE,分页里默认也是使用query_strings'的方式来传递参数的,所以在页面传值和接收参数的时候。就需要使用$_GET['']的方式来获取。
是的,只要你修改一下你的分页代码。把
$config['base_url']=site_url('compmanage/compinfolist/'); 改成 $config['base_url']=site_url('?c=compmanage&m=compinfolist');
把      $config['uri_segment'] = 3; 改成 $config['query_string_segment']='per_page';
再把$query=$this->db->get('',$config['per_page'],$this->uri->segment(3));改成$query=$this->db->get('',$config['per_page'],$_GET['per_page']);就可以了。但此时路径显示的是http://localhost/site/index.php/?c=compmanage&m=compinfolist&per_page=1这样的一个地址,我看着不舒服。于是看如何把CI分页里默认就自动转变为这种方式的传值改变一下。令他还是使用原来的PathInfo方式传取。
很简单。只要把CI / System / libraries / Pagination.php 打开编辑.
把125行开始的
   if ($CI->input->get($this->query_string_segment) != 0)
   {
    $this->cur_page = $CI->input->get($this->query_string_segment);
   
    // Prep the current page - no funny business!
    $this->cur_page = (int) $this->cur_page;
   }
屏蔽掉,换成以下代码
   if ($CI->uri->segment($this->uri_segment) != 0)
   {
    $this->cur_page = $CI->uri->segment($this->uri_segment);
   
    // Prep the current page - no funny business!
    $this->cur_page = (int) $this->cur_page;
   }
再把下面一百八十多行里的
if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE)
{
   $this->base_url = rtrim($this->base_url).'&'.$this->query_string_segment.'=';
}
屏蔽掉改成
if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE)
{
   $this->base_url = rtrim($this->base_url, '/') .'/';
}
OK了。大功告成, 现在分页还是使用原来的pathinfo方式。不过要记住,如果CI要升级了。一定要再一次把这个分页类修改过来。
页: [1]
查看完整版本: CI设置 'enable_query_strings'为 TRUE后的分页使用Pathinfo的问题