doqp87012 2017-05-02 11:25
浏览 78
已采纳

在Codeigniter分页中设置当前页面

Below is my code, I don't know why it always keeps 1st page as current page. And that's why NEXT link is also not working. I also tried $config['uri_segment'] = 1; But not working. Where is the problem ?

$data['mukkadam_list'] = $this->get_mukkadam();
$data['from']      = $from;
$data['to']        = $to;
$data['mukkadam']  = $mukkadam;
$url = base_url('Report/teee/'.$from.'/'.$to.'/'.$mukkadam);
$config['base_url']   = $url;
$config['per_page']   = 50;
// Reports is model. 
$config['total_rows'] = $this->Reports->counter($data['from'],$data['to'],$data['mukkadam']);
$config['num_links'] = $config['total_rows']/50;

$this->load->library('pagination');
$this->pagination->initialize($config);

thank you. :)

  • 写回答

3条回答 默认 最新

  • drk49438 2017-05-02 12:06
    关注

    You need to remember two things whenever you are going to implement pagination in Codeigniter:

    First thing Configuration related to page generation which is actually:

        // Loads pagination library
        $this->load->library('pagination');
    
        // @params $url = your controller + method path
        $config['base_url'] = base_url() . $url;
    
        // @params $totalRows = Total  result found in query
        $config['total_rows'] = $totalRows;
    
        // @params $perPage = In your case it is 50
        $config['per_page'] = $perPage;
    
        // @params $segment = This is what you are missing in your code. Segment is the factor from where system reads which page records need to be shown
        $config['uri_segment'] = $segment;
        $this->pagination->initialize($config);
    

    Second Thing Pagination configuration related to designing part:

    $config['full_tag_open'] = '<ul class="pagination  pagination-sm m-t-none m-b-none">';
    $config['full_tag_close'] = '</ul>';
    $config['prev_link'] = '<i class="fa fa-chevron-left"></i>';
    $config['prev_tag_open'] = '<li>';
    $config['prev_tag_close'] = '</li>';
    $config['next_link'] = '<i class="fa fa-chevron-right"></i>';
    $config['next_tag_open'] = '<li>';
    $config['next_tag_close'] = '</li>';
    $config['cur_tag_open'] = '<li class="active"><a href="#">';
    $config['cur_tag_close'] = '</a></li>';
    $config['num_tag_open'] = '<li>';
    $config['num_tag_close'] = '</li>';
    
    $config['first_tag_open'] = '<li>';
    $config['first_tag_close'] = '</li>';
    $config['last_tag_open'] = '<li>';
    $config['last_tag_close'] = '</li>';
    
    $config['first_link'] = '<i class="fa fa-chevron-left"></i> <i class="fa fa-chevron-left"></i>';
    $config['last_link'] = '<i class="fa fa-chevron-right"></i><i class="fa fa-chevron-right"></i>';
    $this->pagination->create_links();
    

    This is the running script which I have been using in my projects. Working fine. You need to check uri_segment you are passing during initialization.

    Let me know if you face any issue.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?