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]+'
        )
	);

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.