Getting last query on CakePHP when you need to exit in the middle of the action is pretty annoying. You would usually do a function where the dataSource would be instantiated and then you would access the queryLog.
function getLastQuery()
{
$dbo = $this->getDatasource();
$logs = $dbo->_queriesLog;
return end($logs);
}
On CakePHP 2.x the _queriesLog is protected so you can’t access it directly. After a little search found out a great way to do it:
$log = $this->Model->getDataSource()->getLog(false, false); debug($log);
This was explained in this post: http://blog.tersmitten.nl/archives/1172 and it does works wonders. All you need to do is to change the "Model" for your model name.
Amazon MP3 Store



