Code snippets for symfony 1.x


Refine Tags

Snippets tagged "debug"

Hide Web Debug Details and show it on errors

This snippet hides the Web Debug details and show it automatically whenever an error has detect by the Debug System.

This code uses a JavaScript file only for development environment, avoiding unnecessary requests and extra codes in production environment and files.

Obs: Requires jQuery JavaScript Library.

1) Copy the code below and save it as a JavaScript file in "/web/js/debug.js"

    //sfWebDebug Bar Toogler
    var JQsfWebDebug = $('#sfWebDebugDetails');
    (JQsfWebDebug.children('li').hasClass('sfWebDebugError')) ? : JQsfWebDebug.hide();

2) Place the PHP code below in your "/apps/application-name/config/view.yml"

  // your metas, styles, etc... configuration
  javascripts:    [yourScript.js <?php if(sfConfig::get('sf_web_debug')) echo ',debug.js' ?>]

Tip: You can use "debug.js" for all JavaScript debug needs.

by Mario Rezende on 2011-01-15, tagged debug  javascript 

Debug an object or variable with additional informations

This function allows you to dump the value of a variable or an object.If available the function tells the file, line, function, class where it was called.

1st parameter

The object/variable to debug

2nd parameter

The name that you want to give to the debuged object (var by default)

3nd parameter

Allows you can stop the process or not. If the process is not stopped the debug message is available in the sf debug bar.

   * Function that dumps an array or an object in the SF debug infos or
   * on s"\n"een/console
   * @param $var mixed variable to dump
   * @param $die boolean Tells the function to stop the process or not
   * @author Vernet Loic
   * @since  24 sept. 2006
  public static function dump($var, $name = 'var', $die = false)
      print('<br/><pre>'. $name . ' :<br/>');
      $buffer = ob_get_contents();
      $backtrace = debug_backtrace();
      $dieMsg  = '<pre><b>var dump by goTools:dump()</b>'. "\n";
      $dieMsg .= isset($backtrace[0]['file']) ?     '» file     : <b>'.
      $backtrace[0]['file'] .'</b>'. "\n" : '';
      $dieMsg .= isset($backtrace[0]['line']) ?     '» line     : <b>'.
      $backtrace[0]['line'] .'</b>'. "\n" : '';
      $dieMsg .= isset($backtrace[1]['class']) ?    '» class    : <b>'.
      $backtrace[1]['class'] .'</b>'. "\n" : '';
      $dieMsg .= isset($backtrace[1]['function']) ? '» function : <b>'.
      $backtrace[1]['function'] .'</b>'. "\n" : '';
      $dieMsg .= '</pre>';
      if ($die == true) {
      } else {
by Loïc Vernet on 2007-12-20, tagged debug 

Bookmarklet to toggle between dev & prod environments

The following bookmarklet toggles between the dev and prod environments. It simply does that by adding or removing the '_dev' suffix before the first ".php" of the URL.

javascript:var parts=location.pathname.match(/(.*?)(_dev)?(\.php.*)/);location.pathname=parts[1]+(parts[2]?'':'_dev')+parts[3]
by Michel D'HOOGE on 2007-08-31, tagged bookmarklet  debug 
(1 comment)

Correct defect anti-aliasing of Gecko engines, displaying WebDebugBar

If you are displeased having different anti-aliasing of fonts in your Gecko Browsers (Camino, Firefox, Flock), when WebDebug is on. Gecko Browsers will show the fonts more thiner. But when you close WebDebug, the fonts will be normal again.

I think that this is not a acceptable casualty, so i deactivate the semi-transparence of the Bar. This will correct the behavior of the Gecko engine.

Just put the code in your css file (don't modify the css of web debug):

#sfWebDebugBar, .sfWebDebugCache {
  opacity: 1;
by Halil Köklü on 2007-06-25, tagged css  debug 
(1 comment)

Hide Web Debug Details on Launch.

If you want to hide the Web Debug Details/Menus but also want to have quick access when you need it.

Then this could help you. Just copy this in a js file or print it in your layout:

Event.observe(window, 'load', function(){
    // check if web debug is on
    if ($('sfWebDebugBar'))
by Halil Köklü on 2007-06-25, tagged debug  javascript 

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>";
    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)

Dump variables/objects to screen

Sometimes a set of circumstances will arise when the programmer is not certain what objects are available to a particular point of a symfony app (the manual is, at the time of writing, not entirely exhaustive).

Simply pop this code in your code temporarily and the output should give you some clues.

$vars = get_defined_vars();
foreach($vars as $key => $val) {
  $t = gettype($$key);
  echo "${key} (${t})<br />";
by halfer on 2006-06-02, tagged debug  objects  variables 
(1 comment)

Hide debug screen by actions.

If you do not want to display debug screen (Ajax or feed etc),add following code each action.

sfConfig::set('sf_web_debug', false);
by Yoshihiro TAKAHARA on 2006-05-22, tagged debug