Pager (v.1.x) vs. Pager_Sliding

Pager (v.1.x) vs. Pager_Sliding – Feature comparison of the two classes

What are the differences with Pager?

While Pager v.1.x has a "jumping window" style, Pager_Sliding has a "sliding window" style. What does that mean? Let's see an example:

Pager v.1.x logic

Let's suppose that the data spans on 15 pages, and the window width is 5 page links. The links are built on "frames" of 5 pages each: [1-5] [6-10] [11-15] Pager v.1.x always shows the same 5 page links while you are on one of these pages. Here's a temporal succession of the links, starting from page 1 and moving forward. There are brakets around current page number to highlight this:

<?php
a
)    {12  3  4  5  =>   // first frame: [1-5]
b) <=  {23  4  5  =>
c) <=  1  2 {34  5  =>
d) <=  1  2  3 {45  =>
e) <=  1  2  3  4 {5} =>   // HERE IT JUMPS TO THE NEXT FRAME
f) <= {67  8  9 10  =>   // second frame: [6-10]
g) <=  {78  9 10  =>
h) <=  6  7 {89 10  =>
?>

and so on. See what a "jumping window" frame is? When you reach a limit (in the example, you go from page 5 to page 6), it "jumps" to next frame (links from page 6 to 10).

Pager_Sliding logic

Instead of jumping from one frame to the other, with Pager_Sliding the change is done smoothly, and the current page is always shown at the center of the "window" (except of course for the first and the last pages):

<?php
a
)       {12  3  4  5  => [15]
b) [1] <= {23  4  5  => [15]
c) [1] <= 1  2 {34  5  => [15]  // HERE IT's STARTING WORKING AS DESIGNED
d) [1] <= 2  3 {45  6  => [15]  // see: current page number is at the center of the window
e) [1] <= 3  4 {56  7  => [15]  // and it stays there...
f) [1] <= 4  5 {67  8  => [15]
g) [1] <= 5  6 {78  9  => [15]
h) [1] <= 6  7 {89 10  => [15]
?>

and so on.

Other differences

Apart from the different "philosophy", Pager_Sliding is also designed to be highly customizable.

UPDATE: since Pager 2.x release, every option once only available in Pager_Sliding is now fully implemented in Pager too, and more. As stated in the Intro, Pager_Sliding is now deprecated in favour of the new Pager v.2.x. You can have both behaviours ("Jumping" and "Sliding") in Pager v.2.x, just change the mode. Please refer to Pager docs for more details.

  • There are *many* options to change the look and feel of the links in your page. They are explained in the constructor docs.

  • It can work with Apache mod_rewrite module too, see the examples for that.

  • It is "template"-friendly, i.e. you can assign the processed links and page numbers to your custom vars and use them to draw your link bar according to your page layout, without worrying about the underlying logic.

  • You can easily extend the class; this is useful if you plan to use the class in many different pages and you don't want to set the same options everytime: just set your preferred default values in your extending class and you're done!

    Поддержать сайт на родительском проекте КГБ