A good example of when you would need this is if the underlying DB does not support the SQL LIMIT syntax. This is true of IBM’s DB2. You can still use the CakePHP pagination by adding the custom query to the model.
Should you need to create custom queries to generate the data you want to paginate, you can override the paginate() and paginateCount() model methods used by the pagination controller logic.
2. CakePHP Advanced Pagination – sort by derived field
I spent a couple of hours to find out a way… and finally got it! yes it is possible to sort by derived fields using the built-in pagination feature of cakephp! Let’s talk about the solution a little later, first I’d like to introduce you with the exact problem I faced.
What I’m going to talk about is how to mix your custom find types with pagination, without having to use paginate and paginateCount in your models.
To continue on last weeks thought of a “lite” forum, I needed 2 tables (Forums, Posts). Since this is a “lite” forum, I did not want to create a mid-table labeled topics, so I incorporated that in the Posts table. The other reasoning behind this, is that to create a hybrid forum/blog, the topic is really just a beginning post in the thread, so keep those in the Posts table, just mark it as a topic to differentiate this from the other posts.
Pagination is something that any decent site has in it somewhere. The whole idea is to give the user pages of information to look through, instead of just listing all the data at once. Not only does this cut down on page load times, but it is also a great way to view and organize the information as well. And like always, Cake makes this task just as easy as a few lines of code.