简体   繁体   中英

Codeigniter customizing pagination links

I'm using CodeIgniter pagination,Consider 20 links pagination

Condition 1 : Show 5 links initially like below

1 2 3 4 5 next>>

Condition 2 : When 5th link is clicked, the number 5 should place two digits on either side like below

<<previous 3 4 5 6 7 next>>

I have change

$config["num_links"] = 2;

this works fine for condition 2 but initially it gives 3 links like below.

 1 2 3 next>>

When num_links changed to 4

$config["num_links"] = 4;

this works fine for condition 1 but fail to meet condition 2

CodeIgniter does not have any inbuilt configuration for this.

When you say: $config["num_links"] = 2; it just means add 2 previous and 2 next to the current page.

When you are in the first page, there is no previous and it adds two next so you get:

1 2 3 next>>

Same logic for the behavior when you do $config["num_links"] = 4;

If you really want to do it how you described you will have to extend the CI Pagination class with your own class:

class MY_Pagination extends CI_Pagination {...

And then add your custom pagination functions to it.

This link looks like an interesting read and may help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM