function lastQuery(){
$dbo = $this->getDatasource();
$logs = $dbo->_queriesLog;
// return the first element of the last array (i.e. the last query)
return current(end($logs));
}
然后可以运行以打印输出:
debug($this->lastQuery()); // in model
或者
debug($this->Model->lastQuery()); // in controller
2. 呈现 SQL 视图(模型中无效)
To print out all queries run in a given page request, in your controller (or component, etc) run:
$this->render('sql');
It will likely throw a missing view error, but this is better than no access to recent queries!