In applying the answer from a previous question, I tried overriding one of CakePHP’s built-in pagination methods:
function paginateCount($conditions = null, $recursive = 0, $extra = array()) {
if (isset($extra['group'])) {
for ($i=0; $i<count($extra['group']);$i++) {
if (strpos(strtolower($extra['group'][$i]),'having')!==false) unset($extra['group'][$i]);
}
exit();
}
$count = parent::paginateCount($conditions, $recursive, $extra);
return $count;
}
The problem is that this seems to cause Cake to do a MySQL query consisting simply of the name of the method. Obviously this doesn’t work and throws an error:
SQL Error: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘paginateCount’ at line 1
Since I have debugging enabled, I can see that where there would normally be the paginateCount() query:
1: SELECT COUNT(*) AS `count` FROM `tournaments` AS `Tournament` WHERE 1 = 1
I just get:
1: paginateCount
I’ve obviously misunderstood PHP’s inheritance operators. My function seems to be returning the name of the function it is overriding rather than it’s value.
How can I fix this?
This usually happens when CakePHP can’t find the method in the model or attached behaviors.
It then passes the call to the datasource (hoping it has the method and knows what to do) and that’s why you get this error.
I would check things are what they seem (is the method in the right model, is Cake making an automodel because of incorrect filenaming, etc.)