Friday, May 28, 2010

No more print_r's or var_dumps to the web browser

Here is a neat way to dump objects to the log file instead of the browser, just add the following function to your actions class

class yourActions extends sfActions

/**
other code...
**/

/**
* Just a neater way of dumping objects to the log file instead of the browser
*
* @param $foobar
* @param $priority
* @author Richard Udovich
* @return void
* @see self::logMessage()
*/
public function logFoobar($foobar, $priority = 'info') {
if (in_array('Doctrine_Record', class_parents($foobar))) {
$table_name = $foobar->getTable()->getClassnameToReturn();
$this->logMessage('Dumping '.$table_name. "\n".print_r($foobar->toArray(), true).')', 'debug');
}
}

No comments: