1
The The Cakephp Manual suggests a change in default pagination for custom queries cases and in some cases my project has worked perfectly. But I have a situation where I have several custom queries and I need to make the pagination in all of them (these 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 several 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');
It may explain your specific problem better, and why the manual method does not work in your case?
– bfavaretto
@bfavaretto, does not work because it does not meet my criteria. It has formatting, conditions and others that the basics of Cake does not provide me. As for explaining better, what don’t you understand? I need to do the paging in all custom queries and the Cake manual does not address this, I need to know how to do.
– Danilo Miguel
@Danilomiguel has how to post an example of one of these custom queries that you are doing and how you are working with paging so we can try to better understand what you have already done?
– Tafarel Chicotti
@Tafarelchicotti includes in the body of the question an example of query. As for paging, I’m not doing anything yet because besides the example query, I have at least 6 other different.
– Danilo Miguel
Which version of the cake you are using?
– Tafarel Chicotti
@Tafarelchicotti, use the 2.x.
– Danilo Miguel
The @gildonei response was perfect
– Erlon Charles
Yeah, it took me a while to get back here :) So Danilo, as you saw in @gildonei’s reply, can avoid custom paging by forcing joins or using Containable behavior. Still, in certain cases it may be necessary to use this.
– bfavaretto