I’m creating a Blog in Yii at the moment. One sticking point I’m having is how to get the navigation system they’ve asked for to work the Yii way… They’ve asked that clicking on a month takes you to the articles for that month (most recent first), with at-most X per page (X should be user-definable), but for no page to ever mix months…
There are 10 articles, June has 6 posts, May had 4, and X=5. This should be spread across 3 pages, two for June (with 5 and 1 articles), and one for May (with 4 articles).
I’m thinking this doesn’t really fit with CPagination that well… My current plan is to limit the Pagination to within the month (June shows two pages) and override the next and previous buttons (rendered in the ListView) so that they jump to the start of the next month/end of the previous month if there are no more pages.
Any better ideas for how to make it work? I think that the pages would ideally be listed as June p1, June p2, May p1. I have the query sorted-out for pulling the counts for the various months, I’m just trying to figure-out if it’s worthwhile overriding CPagination to make it possible.
$criteria = $model->dbCriteria; $criteria->mergeWith(array( 'select'=>"YEAR(`Publish`) AS Year, MONTH(`Publish`) AS Month, COUNT(*) as Count, CEILING(COUNT(*)/5) as Pages", 'group'=>"YEAR(`Publish`), MONTH(`Publish`)", 'order'=>"`Publish`", )); $data = $model->commandBuilder-> createFindCommand($model->tableName(),$criteria)->queryAll();
My idea is to sum the Count and Pages columns in PHP to get the total number of pages and total number of items, but how to integrate this with CListView to make it work is a little beyone me. Any ideas?