Paginating a custom find type
The recipe, Implementing a custom find type, showed us the power of extending the built-in model find types, including support to use the implemented custom types for fetching records or counting them.
Now that we know how to fetch and count custom find types, we can easily paginate a set of resulting rows. This recipe shows how to use CakePHP's built-in pagination support to paginate a set of rows that come as a result of a custom find type.
Getting ready
We need some sample models and data to work with, and we need the override of the find()
method in AppModel
to allow count
operations on custom find types. Therefore, make sure you follow the entire recipe, Implementing a custom find type, including its Getting ready section.
How to do it...
1. Create a file named
posts_controller.php
in yourapp/controllers
folder. If you already have one, make sure itsindex()
method is as follows:<?php class PostsController extends AppController { public function index(...