0
votes

I'm using CakePHP v2.42 & would like to have SEO friendly URL in page pagination.

My current pagination is like

http://www.website.com/ubs/page/page:2

What to do to change to

http://www.website.com/ubs/page/2

My Controller is

<?php
  class UbsController extends AppController {

  public $helpers = array('Html', 'Form');

  public function index() {

    $this->paginate = array(
    'limit' => 100,
    );

    $ubs = $this->paginate();

    $this->set('ubs', $ubs);
}}

My Router is

Router::connect('/ubs', array('controller' => 'ubs', 'action' => 'index'));
Router::connect('/ubs/page/*', array('controller' => 'ubs', 'action' => 'index'));

EDIT - ADD MORE QUESTION

Answer by @kicaj is perfectly correct for the Router & Controller. However, the navigation link only display correctly on the first page.

In the first page navigation link show like this which is correct

http://www.website.com/ubs/
http://www.website.com/ubs/page/2/
http://www.website.com/ubs/page/3/

But navigation link show like this in second/third page page

http://www.website.com/ubs/index/2/
http://www.website.com/ubs/index/2/page:3/

I guess need to edit index.ctp file but not sure what to do.

My current navigation link in index.ctp show like this

$paginator = $this->Paginator;
$paginator->prev("« Prev");
$paginator->numbers(array('modulus' => 200, 'separator' => ' '));
$paginator->next("Next »");

What to change to correct this

2

2 Answers

0
votes

In your Paginator Helper you can choose the right friendly url you want with setting some options

  • url The URL of the paginating action. ‘url’ has a few sub options as well:
    • sort The key that the records are sorted by.
    • direction The direction of the sorting. Defaults to ‘ASC’.
    • page The page number to display.

There here an example .

$this->Paginator->options(array(
    'url' => array(
        'sort' => 'email', 'direction' => 'desc', 'page' => 6,
        'lang' => 'en'
    )
));

the source : Modifying the options PaginatorHelper uses

0
votes

Try this:

Router::connect('/ubs/page/:page', array(
    'controller' => 'ubs',
    'action' => 'index'
), array(
    'pass' => array(
        'page'
    ),
    'page' => '[\d]+'
));

and in index action in ubs controller add code bellow:

public function index($page = 1) {
    // ...
    $this->request->params['named']['page'] = $page;
    // ...
}