4
I want to get the last query executed by Cakephp
Example
$data = $this->Ticket->find('all', array('conditions' => $conditions, 'order' => array('Ticket.id' => 'DESC')));
$this->query = $this->Ticket->getLastQuery();
public function getLastQuery($fromWhereClause = false){
$dbo = $this->getDatasource();
$logs = $dbo->getLog();
$lastLog = end($logs['log']);
if ($fromWhereClause) {
return strstr($lastLog['query'], 'WHERE');
}
return $lastLog['query'];
}
but getLastQuery is only executed when debug is set to 2 would like to achieve with the value set to 0
It only works with debug enabled, because it uses the cake debug log, as far as I know, I would need to implement something like this directly in the lib model.
– Marcelo Aymone
Apparently its function is OK, but this works -<? php end($this->Modelname->getDataSource()->getLog()['log'])['query']? >, whereas you are running this code in the controller.
– Gildonei