0
votes

I am fetching the records from the database & displaying as a table view., I've come across through a problem that,I'm taking the value from the db directly but displaying the count of that field.

If I wanna make sorting I need to sort on the count of the field but I dont have the count value in the db directly

For eg..

If this is my sorting through Paginator..

$this->Paginator->sort('user_id', 'User account');

I need to sort on count(user_id) as I am displaying the count of the user_id, but I was unable to do that through the paginator helper..

1

1 Answers

2
votes

Use virtual fields

http://book.cakephp.org/2.0/en/models/virtual-fields.html

CakePHP GROUP and COUNT items returned in list

var $virtualFields = array(
    'user_count' => 'COUNT(user_id)'
);