You can implement custom pagination, see Custom Pagination in the Cookbook. However, it looks like what you are doing can be accomplished with grouping and the SQL SUM function so that you can just use the built-in pagination. Example:
$alias = $this->Pbscodemetric->alias; $this->Pbscodemetric->virtualFields = array ( 'downloads_iphone_sum' => sprintf('SUM(`%s.downloads_iphone`)', $alias), 'downloads_ipad_sum' => sprintf('SUM(`%s.downloads_ipad`)', $alias), 'downloads_android_sum' => sprintf('SUM(`%s.downloads_android`)', $alias) ); $this->paginate = array ( 'fields' => array ( 'downloads_iphone_sum', 'downloads_ipad_sum', 'downloads_android_sum', 'created' ), 'group' => 'created', 'order' => array ( 'created' => 'desc' ), 'limit' => 10 ); $data = $this->paginate($alias);
This will give you compatible Paginator results with the summarized columns downloads_iphone , downloads_ipad and downloads_android columns grouped by created . It uses virtual fields to return CakePHP-style default results, meaning they will be available as follows:
<?php foreach($results as $result): ?> <tr> <td><?php echo $result['Pbscodemetric']['created'];?></td> <td><?php echo $result['Pbscodemetric']['downloads_iphone_sum'];?></td> <td><?php echo $result['Pbscodemetric']['downloads_ipad_sum'];?></td> <td><?php echo $result['Pbscodemetric']['downloads_android_sum'];?></td> </tr> <?php endforeach; ?>
source share