Code snippets for symfony 1.x

Navigation

Refine Tags

Snippets tagged "object debug"

Debug an object or variable (easy way)

This in the easiest way (I found) to debug an object (or variable).

In an action

$this->debugMessage(sprintf('<h1>object</h1><pre>%s</pre>', print_r(@$this->object, true)));

In a template

<?php use_helper('Debug') ?>
<?php echo debug_message(sprintf('<h1>object</h1><pre>%s</pre>', print_r(@$object, true))) ?>

Based on symfony book debug page.

by brikou on 2006-06-24, tagged debug  object 
(1 comment)

debug objects or variables...

my approach to the previous snippet is to create a class called debugTools.class.php and throw it in the \lib directory. It should contain the following code:

<? 
 
Class debugTools {
 
/**
* renders to the page a proper object map for looking over contents of an object as it occurs.
*
* @param    object       $object        (required) the object for inpection
*/
Public Static function inspect($object)
    {
    echo "<PRE>";
    print_r($object);
    echo "</PRE>";
    }
 
 
}// ends class  
?>

you can then call it easily (with only two or three keystrokes if your IDE does autocompletion) by calling:

echo debugTools::inspect($object);

the resulting formating looks like so (i used it to analyze a usp shipping object):

ups Object
(
    [_errors] => Array
        (
        )
 
    [_action] => 3
    [_delivery_code] => GND
    [_src_country] => US
    [_dst_country] => US
    [_rate_chart] => 5
    [_container] => 0
    [_rescom] => 1
    [_rate_charts] => Array
        (
            [0] => Regular+Daily+Pickup
            [1] => On+Call+Air
            [2] => One+Time+Pickup
            [3] => Letter+Center
            [4] => Customer+Counter
            [5] => Drop+Off
        )
 
    [_containers] => Array
        (
            [0] => 00
            [1] => 01
            [2] => 21
            [3] => 22
            [4] => 23
            [5] => 1
            [6] => 2
        )
 
    [_rescoms] => Array
        (
            [0] => 1
            [1] => 2
        )
 
    [_src_zip] => 97499
    [_dst_zip] => 90120
    [_weight] => 2
)

a handy way of viewing objects that can be accessed from the layout or pretty much anywhere, if you're new to symfony use it to look over $sf_user in the template, you will have a much better idea what's going on.

by Russ Cann on 2006-06-02, tagged debug  object  variables 
(1 comment)