views:

2270

answers:

3

When I use CakePHP Paging I get an url like this:

http://example.com/php/page:2

What do I have to change in the controller, the view and the routes.php to create a working url like this:

http://example.com/php/2
+1  A: 

Oh yes, now I see your question. Well you could do something like:

function index($page){
  $this->paginate = array('page'=>$page);
  $this->set('stuff', $this->paginate('YourControllerName'));
}

See here for more details: http://bakery.cakephp.org/articles/view/basic-pagination-overview-3

Also, of course you should do some validation that the page is an actual number and that the page would even exist but that is the basics of it i think.

About the routes and views, I have never tried but have a look at these posts on the cake groups, I think they have a problem similar to yours.

http://www.mail-archive.com/[email protected]/msg45878.html

jimiyash
I think you misunderstood me, I want to create different Paging-URL's. In CakePHP you can use the Pagination function to split data between different pages. The URL is auto-created by CakePHP and "page:2" means: show me the data which didn't fit on the first page (like the first 15 items), "page:3" would then show me the elements 30-45 etc.
nolandark
A: 

My guess is that this won't be easy to automate, you'll definitely need to do some tweaking.

For starters, you'll probably have to create your own paginator helper and inherit the default one. By the looks of the code, you'll need to override the link-generating code in PaginatorHelper::__pagingLink(), but probably numbers() and prev() etc.. since they all create links with the page param.

Maybe a better way would be to override your AppHelper::url(), check for the "page" param there and modify the url to accomodate your needs.

But, I haven't tried all this, so no guarantees..

dr Hannibal Lecter
+1  A: 

Try this link:

http://www.sakic.net/blog/changing-cakephp-pagination-urls/

Fabian Brenes