Reputation: 3170
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 right now see following links
prev, 1(selected), 2, 3, 4, 5... next
user clicks on, say 4, now he sees
prev... 3, 4(selected), 5, 6, 7...next
now he clicks on 7
prev... 6, 7(selected), 8, 9, 10...next
How can I do this in code igniter?
Thanks in advance.
Upvotes: 0
Views: 2693
Reputation: 1
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 >>
Upvotes: 0
Reputation: 4305
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......
Upvotes: 0
Reputation: 5352
find Pagination Class in Libraries folder and edit this variable:
var $num_links
Upvotes: 0