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…

Squarespace Image Export

To gain continued access to your Squarespace website images after cancelling your subscription you have several...

MySQL 8.x GRANT ALL STATEMENT

-- CREATE CREATE USER 'tgnrestoreuser'@'localhost' IDENTIFIED BY 'AppleSauceLoveBird2024'; GRANT ALL PRIVILEGES ON...

Exetel Opt-Out of CGNAT

If your port forwards and inbound and/or outbound site-to-site VPN's have failed when switching to Exetel due to their...