This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use Stack Overflow.

dump function

Social code snippet repository

dump function

by COil » Sat Sep 23, 2006 11:27 pm

just a little function to help debug arrays or objects :

The results are in the tab "log & msg" :

Code: Select all
    public static function dump($var, $name= 'var', $die = false)
    {
        ob_start();
        print('<br/><pre>'. $name . ' :<br/>');
        print_r($var);
        print('</pre></br>');
        $buffer = ob_get_contents();
        ob_end_clean();
       
        if ($die == true) {
            die();
        } else {
            print($buffer);
            sfWebDebug::getInstance()->logShortMessage($buffer);         
        }
    }


Use (assuming youput the function in "myTools.class.php") :

Code: Select all
   

$config = SfConfig::getAll();

myTools::dump($config, '$config', true);


[Edit 5 Oct 2006] : Now you don't have to passe the action object, so it will easealy work in all parts of the application.
COil
Faithful Member
 
Posts: 467
Joined: Wed Sep 06, 2006 6:08 pm

Re: dump function

by naholyr » Mon Mar 24, 2008 2:29 am

Why don't you contribute this to snipeets ?
naholyr
Faithful Member
 
Posts: 223
Joined: Mon Jun 25, 2007 11:55 am

Re: dump function

by COil » Fri Jul 04, 2008 1:45 pm

naholyr wrote: Why don't you contribute this to snipeets ?


http://www.symfony-project.org/snippets/snippet/258

:D~ :-D~ :grin:
COil
Faithful Member
 
Posts: 467
Joined: Wed Sep 06, 2006 6:08 pm

Re: dump function

by kurosaki » Wed Aug 20, 2008 6:34 pm

Where I can write this function to be called anywhere in my project? in /lib folder? It must be included somewhere?

Thanks
kurosaki
Member
 
Posts: 70
Joined: Mon Aug 04, 2008 11:47 pm

Re: dump function

by COil » Wed Aug 20, 2008 7:05 pm

?

Code: Select all
$config = SfConfig::getAll();
myTools::dump($config, '$config', true);


So i think a myTools class in the lib folder for exemple.
COil
Faithful Member
 
Posts: 467
Joined: Wed Sep 06, 2006 6:08 pm

Re: dump function

by kurosaki » Wed Aug 20, 2008 8:56 pm

DOes it work on symfony 1.1 ?

I get: Fatal error: Call to undefined method sfWebDebug::getinstance() in /.............../lib/myTools.php on line 32
kurosaki
Member
 
Posts: 70
Joined: Mon Aug 04, 2008 11:47 pm

Re: dump function

by COil » Wed Aug 20, 2008 9:25 pm

No, in fact i have commented this line in my function as i never use it.

Code: Select all
//sfWebDebug::getInstance()->logShortMessage($buffer);
COil
Faithful Member
 
Posts: 467
Joined: Wed Sep 06, 2006 6:08 pm