![]() |
|
Snippets |
|
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]
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:
/* * HIDE WEB DEBUG DETAILS ON LAUNCH */ Event.observe(window, 'load', function(){ // check if web debug is on if ($('sfWebDebugBar')) sfWebDebugToggleMenu(); });
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.
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 />"; }
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 { filter:alpha(opacity=100); -moz-opacity:1; opacity: 1; }
If you do not want to display debug screen (Ajax or feed etc),add following code each action.
sfConfig::set('sf_web_debug', false);
This in the easiest way (I found) to debug an object (or variable).
$this->debugMessage(sprintf('<h1>object</h1><pre>%s</pre>', print_r(@$this->object, true)));
<?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.
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.
The object/variable to debug
The name that you want to give to the debuged object (var by default)
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) { ob_start(); print('<br/><pre>'. $name . ' :<br/>'); print_r($var); print('</pre></br>'); $buffer = ob_get_contents(); ob_end_clean(); $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>'; print($buffer); if ($die == true) { die($dieMsg); } else { print($dieMsg); sfWebDebug::getInstance()->logShortMessage($buffer); } }