When trying to sort data using the CakePHP Paginator, it is returning case-sensitive sort results. I have tried adding UPPER around the field I specify in the order query, but that doesn’t seem to be working. I’m using CakePHP 2.0.3 with a PostgreSQL database. My $paginate variable and the code to call it are:
var $paginate = array(
'limit' => 25,
'order' => array(
'User.first_name' => 'asc'
)
);
..
(In my view function)
$users = $this->paginate('User');
How can I force CakePHP to return a case-insensitive sort result?
It is a shame that you can’t use something like this:
Which would be fairly basic.
I had this issue in a project, whereby I replaced the ‘order’ array with something like this:
which successfully gave me the correct output.
Unfortunately, however, clicking the column header fields to sort my paginated table then replicated the issue, whereby my names were once again case-sensitive.
The solution that I came up with was to modify the PaginatorComponent of cakephp itself, so that my sort order would always be correct.
In the PaginatorComponent (/lib/Cake/Controller/Component/PaginatorComponent.php) I modified the validateSort function, replacing the following line:
With the four lines below:
It’s not elegant, and is essentially just forcing the ‘UPPER()’ around the field name.
This worked in my particular situation whereby I need to always have case-insensitive queries.