jump to navigation

Log messages to SQL debug window August 23, 2006

Posted by rossoft in CakePHP.

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->_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->logQuery(“<span class=\”query_log\”>[{$this->name}] $msg</span>”);


1. Yamagishi - June 7, 2007
2. Window Film - September 23, 2008

Oh my god thank you so much for this!
This has been so helpful to me!
You’re genius.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: