How to make a slug pagination in Cakephp?

4

Cakephp by default generates a pagination with indexes, for example:

noticias/listar/page:2

I would like to paginate this way:

notícias/listar/2
    
asked by anonymous 19.05.2014 / 20:27

1 answer

4

app / config / routes.php

Router::connect('/noticias/:slug', array('controller' => 'noticias',
         'action'=>'listar', 'slug'=> '[0-9a-zA-Z]+'));
Router::connect('/noticias/:slug/:pagina', array('controller' => 'noticias',
         'action'=>'listar','slug'=> '[0-9a-zA-Z]+','pagina'=>'[0-9]+'));

NewsController:

$this->paginate = array(
//outras coisas aqui
'paramType' => 'querystring'
 );

View Listing:

$slug = $this->params['slug'];
$this->Paginator->options(array('url'=> array('controller' => 'noticias',
                              'action'=>'listar','slug'=> $slug),
                                 'convertKeys' => array('page')));

I think that's it, you need to set the cake routes so he understands what you want to request.

    
19.05.2014 / 20:53