3
votes

I have a standard cakePHP backend but I'm not using the cake pagination helper. My existing frontend provides pagination params in the form "startIndex, numberOfResults" vs. "page". It would be great if from within the controller action I could just parse my startIndex, numberOfResults params, calc the proper page and then do something like:

paginate['page'] = $pageNumber;

before the paginate() call. No such luck. So my question is, how can I set the paginator page from within the controller? As a bonus: Where is cake parsing the page named param? Where does it store the page value used for the paginate call?

1
$this->paginate['page'] = $pageNumber; should work, must be done BEFORE the paginate() command, also you can do a paginate on the fly to set some parameters without touching the paginate, you can change also the passed args before calling it... number of results is control with limit option also you can override paginate(), paginateCount() in your model and do it as you wish :D, remember that paginate is just a find('all') that you can override to fit your needs as a custom query :D and leave the rest to do its magicapi55
Changing $this->params['named']['page'], and $this->paginate['page'] doesn't work for me. I think "... without touching the paginate ..." might be my soln. Never noticed the 'page' find option until now. For others - if you use the 'page' find option, don't forget to set 'limit' and 'order' as well.GTM
FYI: Not sure if it matters, but this particular site is a 1.2 site.GTM
It's weird that neither of those worked, if you post some of the code where you do the call, maybe we can help you more :D. Also the paginate function is in cake/libs/controller/controller.php i don't recomend to change it there... anyway you can override how it does the find with any param you want doing a paginate function in your modelapi55

1 Answers

0
votes

Since It's a 1.2 application. You should try changing $this->params['url']['page'] like this:

      $this->params['url']['page'] = $pageNumber;

Source: CakePHP 1.2