The CakePHP manual suggests a change in the default paging for cases of custom queries and in some cases my project has worked perfectly. But I have a situation where I have several custom queries and I need to do the pagination in all of them (they are very specific reports, which the Cake standard does not meet).
In the case of the manual, it informs the change only for a specific case, but in these cases with multiple queries, how to proceed?
Example of a custom query I'm using:
$data = $this->Negociacao->query('SELECT
Consultor.nome,
Cliente.nome,
Negociacao.id,DATE_FORMAT(Negociacao.created,"%d/%m/%Y") AS data,SUBSTR(Negociacao.empresa,1,15) AS empresa,SUBSTR(Negociacao.assessoria,1,15) AS assessoria,
Situacao.nome,
CASE WHEN Negociacao.negociacao_status_id != 3 THEN
DATEDIFF(NOW(),Negociacao.created) ELSE NULL END
AS dias,
CASE WHEN Negociacao.negociacao_status_id != 3 AND DATEDIFF(NOW(),Negociacao.created) > 3 THEN "Y" ELSE "N" END AS atrasado
FROM negociacoes Negociacao
LEFT JOIN clientes Cliente
ON Negociacao.cliente_id = Cliente.id
LEFT JOIN negociacao_status Situacao
ON Negociacao.negociacao_status_id = Situacao.id
LEFT JOIN usuarios Consultor
ON Negociacao.consultor_id = Consultor.id
WHERE Negociacao.consultor_id = '.$consultor.'
ORDER BY data');