Show limited no. of page links in codeigniter pagination

后端 未结 4 587
难免孤独
难免孤独 2021-01-29 03:24

I want to display a limited no. of page links, say 5 out of 10 links,is there any known or tried and tested method in codeIgniter to achieve this.

so lets say user can r

相关标签:
4条回答
  • 2021-01-29 04:06

    When you want to fixed the pagination page number you modify the $num_links:

    $config['total_rows'] =100;
    $config["num_links"] = 5;
    $config['full_tag_open'] = '<ul class="pagination">';
    $config['full_tag_close'] = '</ul>';
    $config['first_link'] = false;
    $config['last_link'] = false;
    

    It shows like this: << 2 3 4 5 6 7 >>

    0 讨论(0)
  • 2021-01-29 04:09

    There's a built in Pagination class for this.

    0 讨论(0)
  • 2021-01-29 04:14

    There is an inbuilt Pagination class provided by codeIgniter. You can find it in user guide.

    Define a start index variable in the function where u want to use pagination as zero.

    public function pagination($start_index = 0)
    

    {

      $result = $this->model->get_results($data); //this $data is the argument which you are passing to your model function. If you are using database to get results array.
    
      $items_per_page = 10;   //this is constant variable which you need to define
    
      $filtered_result = array_splice($result, $start_index, ITEM_PER_PAGE_USERS);
    
      $model['$filtered_result'] = $filtered_result;
    
      $total_rows = count($result);
    
      $model['page_links'] = create_page_links (base_url()."/controlelr_name/pagination",ITEM_PER_PAGE_USERS, $total_rows);
    
      $this->load->view('controller_name/view_file_name', $model);
    

    }

     function create_page_links($base_url, $per_page, $total_rows) {
    
    $CI = & get_instance();
    $CI->load->library('pagination');
    
    $config['base_url'] = $base_url;
    $config['total_rows'] = $total_rows;
    $config['per_page'] = $per_page; 
    
    $CI->pagination->initialize($config); 
    
    return $CI->pagination->create_links();
    

    }

    This create page links function is a generic function.............for more explanation check pagination class from user guide......

    0 讨论(0)
  • 2021-01-29 04:15

    find Pagination Class in Libraries folder and edit this variable:

    var $num_links
    
    0 讨论(0)
提交回复
热议问题