Show limited no. of page links in codeigniter pagination

后端 未结 4 692
难免孤独
难免孤独 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: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......

提交回复
热议问题