in

Snippet : How to Build Better URL CakePHP Pagination Just Like on WordPress

pagination on cakephp

Here is best cakephp snippet to build and rewrite pagination URL. You can build url like this (such as wordpress pagination)

example.com/page/1

example.com/page/2

example.com/page/3

Here is the superb snippet for it

Add this on AppController.php

function beforeFilter(){
		if (isset($this->request->params['page'])) {
			$this->request->params['named']['page'] = $this->request->params['page'];
		}
	}

Add this code to route.php

Router::connect('/page/:page', 
    array('controller' => 'controller', 'action' => 'index'),
    array(
        'pass' => 'page',
        'page' => '[0-9]+'
        )
	);

What do you think?

0 points
Upvote Downvote

Written by Bimo Hery Prabowo

Web developer, big fan of CakePHP, loving wordpress soo much. You can found him on Google+ and Facebook. Dont forget to follow him on Twitter.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.