2
votes

I use cakephp 3.x paginator and I have a request from customer.

Example:

  • My paginate bar, now it's stand at #1.

<< | < | **1** 2 3 4 5 6 7 8 9 | > | >>

  • When I click to ">>" the bar will show 10-19 and stand at #10

<< | < | **10** 11 12 13 14 15 16 17 18 19 | > | >>

  • Click to ">>" again, it will show 20-29 and stand at #20

<< | < | **20** 21 22 23 24 25 26 27 28 29 | > | >>

  • Same with "<<", will back to 10-19 and 1-9.

The ">" and "<" just go next page and back to prev page.

So my question is:

  • How can I make the ">>" and "<<" button with cakephp pagination helper?

My code in view.ctp is

<?php 
  echo $this->Paginator->first(<<);

  echo $this->Paginator->prev('<');

  echo $this->Paginator->numbers();

  echo $this->Paginator->next('>');

  echo $this->Paginator->last(>>);
?>
1
Use single/double quotes with << and >>... first('<<'), last('>>')Poonam
Sorry I didn't understand your meaning.TommyDo
Replace this echo $this->Paginator->first(<<); with this echo $this->Paginator->first('<<'); and same with the lastPoonam
Sorry but it does not suitable with my request. When I click >> it will move to the end of pages.TommyDo
Because first() and last() stands for first and last page simultaneouslyPoonam

1 Answers

1
votes

Unfortunately there is no built-in paginator helper method that would create such links, you may want to file a feature request for that, I think it would be a nice addition.

That being said, you can build such jump links manually, the paginator helper offers everything that is needed, that is, the current page number, a method to check whether a given page exists, and functionality for generating links from the helpers templates.

Here's a basic example, this would generate a jump link for the current page + 10 in case that page exists:

$page = $this->Paginator->current() + 10;
if ($this->Paginator->hasPage($page)) {
    echo $this->Paginator->templater()->format('nextActive', [
        'url' => $this->Paginator->generateUrl(['page' => $page]),
        'text' => '>>',
    ]);
}

See also

Templater docs are currently missing for some reason...