Just Simple Info

Pages

CakePhp Pagination Issue with Group by Solution

It is easy to use in Cakephp it built in pagination in a simple way. But if you will try to use Group By keyword in querying your data. The pagination will return unexpected result. I have notice that the total number of data count is not correct. I Google about this issue, read a blogs and try to run all recommended solution and luckily I found a working one.


Just override a function  paginationCount in your model.

Here is the code snippet.


function paginateCount($conditions = null, $recursive = 0, $extra = array()) {
        
        $parameters = compact('conditions');
        $this->recursive = $recursive;
        
        $count = $this->find('count', array_merge($parameters, $extra));
        
        if (isset($extra['group'])) {
            $count = $this->getAffectedRows();
        }
        
        return $count;
    }


This code is tested in version 1.3.x

No comments:

Post a Comment