Log messages to SQL debug window August 23, 2006
Posted by rossoft in CakePHP.trackback
My models have custom methods that do a lot of findAll(), save() etc. because I want to encapsulate that login on the models. Then the controller calls some of them in one action.
Sometimes, the SQL debug window has a lot of queries, and I don’t know what queries belongs to some method.
Now, I can do
$this->MyModel->_log_info(’test begin’);
$this->MyModel->my_custom_method_that_does_a_lot_of_things();
$this->MyModel->_log_info(’end begin’);
And I see the text ‘test begin’ and ‘end begin’ inside the SQL Debug Window, and between there’s the queries that belongs to ‘my_custom_method’
/**
* Logs the message to the sql debug window
*
* @param string $msg Message to show
*/
function _log_info($msg)
{
if (DEBUG)
{
$db =& ConnectionManager::getDataSource($this->useDbConfig);
$db->error=”;
$db->affected=”;
$db->numRows=”;
$db->took=”;
$db->logQuery(”<span class=\”query_log\”>[{$this->name}] $msg</span>”);
}
}
http://landbest.info/replica-watches/rolex-watch-bezel.php