zhengfeity 发表于 2010-11-6 15:40:36

GET 分页全教程

1.首先在config.php 设置$config['uri_protocol']        = "PATH_INFO";
2.控制器代码
function news()
{
if($_GET['per_page']=="")
    {
      $start_limit=0;
    }else{
   $start_limit=$_GET['per_page'];
    }

    //如果不支持$_GET那么就换成$_REQUEST来接收参数
    $query=$this->db->get('tabel');
    $num=$query->num_rows();
    $conf['per_page']=20;//每页显示数
    $conf['total_rows']=$num;//总共多少行
    $conf['base_url']=site_url()."/news";
    /*
    这样分页的连接就变成了 域名/news?per_page=xxx
    per_page 默认参数 如果想更改请添加
    $conf['query_string_segment']=你要的参数名比如page
    这样开始接收参数也要变成$_GET['page']
    然后分页连接就变成了域名/news?page=xxx
    */
    $conf['page_query_string'] = TRUE;//开GET分页
    $conf['prev_link']="上一页";
    $conf['next_link']="下一页";
    $conf['first_link']="首页";
    $conf['last_link']="尾页";
    $conf['num_links']=5;
    $this->load->library('pagination',$conf);
    $links=$this->pagination->create_links();
    //每页查询开始
    $res1=$this->db->get('tabel',每页几条记录也就是取几条数据,从第几条开始查询这里是接收过来的参数$start_limit);       
    $res=$res1->result();
    然后把你需要的参数 传到视图就完成了

    如果$_GET 不支持的话 需要修改CI分页源码打开library/Pagination.php 找到下面代码
   如果$_GET 支持的话就不需要改了
    if ($this->page_query_string === TRUE OR $CI->config->item('enable_query_strings') === TRUE)
    {
                       
      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 ($this->page_query_string === TRUE OR $CI->config->item('enable_query_strings') === TRUE)
    {
                       
      if ($_REQUEST[$this->query_string_segment] != 0)
        {
                               
        $this->cur_page = $_REQUEST[$this->query_string_segment];
                       
        // Prep the current page - no funny business!
        $this->cur_page = (int) $this->cur_page;
        }
    }

lnlingyuan 发表于 2010-11-6 16:06:51

:lol收下了
页: [1]
查看完整版本: GET 分页全教程