views:

47

answers:

2

Hi,

I'm running in a problem with cakephp pagination. Currently, my pagination is rather standard. After x results, it creates a second page. And so on.

What i would like to do is to order them by month. As it is a news archive, I would like to be able to select the month instead of the page.

So instead:

  • Page 1
  • Page 2
  • Page 3

I would like to have:

  • January 2010
  • February 2010
  • March 2010

How is this possible? I can't seem to find it. My current code:

var $paginate = array('limit' => 50, 'page' => 1, 'order'=>array('Newsitem.created'=>'DESC'));

thanks in advance!!

+1  A: 

Pagination is a function of LIMIT row counts and offsets of number of records, not by data conditions. Therefore, you will not be able to use the pagination function in cake to accomplish this. You will need to create a custom solution to accomplish this. If you continue to solve this with the build in cake pagination, you will continue to hit a brick wall.

Now, that being said, one solution is to paginate by month. So you could have different links down the left showing the months (i.e. January 2010, February 2010, etc.), when they select one of those options, it will paginate all of the results for the given date.

cdburgess
A: 

This might be an alternative you'd consider (it doesn't match your requirement directly).

CakePHP Filter Plugin

What it would allow you is filtering paginated data by any column in the recordset.

Under any header (<th>) you'll be able to add an input where you can enter filter criteria (e.g. for Newsitem.created you could enter: 2010-08 to display/paginate only Newsitems for Aug. 2010). You then click the filter button and your page reloads showing only the records that match the filtered criteria. Works with Ajax pagination also.

I tested this today with this screen:

CakePHP Filter Plugin

Chris