Implementing <<first and last>> links in cakephp pagination

Written by James McDonald

March 6, 2015

I don’t know why they don’t include them by default but here is an example of how to add first and last links to your view.

<?php
    echo $this->Paginator->first('<< first'); #add this
    echo $this->Paginator->prev('< ' . __('previous'), array(), null, array('class' => 'prev disabled'));
    echo $this->Paginator->numbers(array('separator' => ''));
    echo $this->Paginator->next(__('next') . ' >', array(), null, array('class' => 'next disabled'));
    echo $this->Paginator->last('last >>'); # add this
?>

You probably want to look at the css classes that you should apply too.

Of course there are alot more options as with most things you can read the documentation to find out more: http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html

Another option is to use the ‘first’ and ‘last’ options to the numbers method

<?php
	echo $this->Paginator->prev('< ' . __('previous'), array(), null, array('class' => 'prev disabled'));
	echo $this->Paginator->numbers(array('separator' => '', 'last' => "last", 'first' => "first"));
	echo $this->Paginator->next(__('next') . ' >', array(), null, array('class' => 'next disabled'));
?>

 

 

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.

You May Also Like…

Clear HSTS Settings in CHrome

Open chrome://net-internals/#hsts enter the domain in the query field and click Query to confirm it has HSTS settings...

Ubuntu on Hyper-v

It boils town to installing linux-azure # as root or sudo apt-get update apt-get install linux-azure...