Recently, I was asked by yunhaihuang some questions about advanced pagination stuff I couldn’t answer satisfactorily…

And that’s when I realized that the current implementation of the pagination feature of CakePHP contains at least one conceptual flaw (in most pagination scenarios you probably won’t notice this flaw).

Let’s have a look at pagination at the model level. A paginator is in principle a user of the “find” functionality of a model. And as there are many different ways to use this “find” functionality, there can also be many paginators. So we have the following relationship: a model is accessed by many paginators.

In the code you don’t find an explicit paginator object, you define the “paginators” with the $paginate array of the controller. With one exception: if you want to use a custom query for the pagination you have to add and implement the methods paginate() and paginateCount() in your model (see the manual for more details). But there is a snag to it: as soon as you define those methods it is no longer possible to use the default pagination query without workarounds, because now the new methods are always used… So we can say that the implemented concept is: a model has one pagination query which can be accessed by many paginators.

Another thing I wondered at was the pagination helper. Shouldn’t there be different instances of this helper if you want to paginate different data sets on the same page? Currently, there is only one instance, and every method allows you to specify the model name to switch the data set (it assumes there is only one data set per model). But I’m not sure whether the pagination helper is even thought for this use case, at least I couldn’t figure out how to paginate two data sets (without Ajax)…

Hopefully these thoughts help to improve the pagination feature in future versions.