2012-06-29 2 views
1

j'ai créé un itinéraire qui ressemble à ceCakePHP Routes et Pagination

Router::connect('/:slug', array('controller' => 'categories', 'action' => 'view'), 
                array('pass' => array('slug'))); 

Jusqu'à ici, tout fonctionne Okey, visitant le lien http://example.com/animals-and-pets, fonctionne parfaitement.

Sur cette page, j'ai une pagination et cela me donne un gros problème, les liens pour les pages, génèrent mal, comme ceci: http://example.com/categories/view/animals-and-pets/page:2. Le résultat que je veux obtenir est example.com/animals-and-pets/2.

Merci pour votre aide à l'avance!

+0

c'est là le gâteau se complique n_n – pleasedontbelong

Répondre

0

Une fois, je l'ai fait de cette façon: change CakePhp1.3 paginator destination url?

Cependant, il pourrait obtenir beaucoup plus facile si vous utilisez \page:2 au lieu de \2

maintenant dans le gâteau 2.0 j'appelle le $this->Paginator->options() pour définir l'URL correcte dans la voir avant le reste des options de pagination. Quelque chose comme:

//Set the correct url for the pagination, cake will add the "page:" and "sort:" variables to this url 
$this->Paginator->options(array('url'=> array('controller' => 'categories', 'action' => 'view', 'slug' => $this->params['pass'][0]))); 
//now display the pagination 
echo $this->Paginator->counter(array('format' => __('Page {:page} of {:pages}'))); 
echo $this->Paginator->prev('«', array(), null, array('class' => 'prev disabled')); 
echo $this->Paginator->numbers(array('separator' => '')); 
echo $this->Paginator->next('»', array(), null, array('class' => 'next disabled')); 

Hope this helps