if you are developing Modules or Replacementtags for phpwcms or just want to know, what happens inside phpwcms script (which Data holds the $_SESSION var or so) you probably write
Code: Select all
print_r($var)
I do so - and if I need to put out large arrays i will write something like echo "<pre>";print_r($var);echo"</pre>"; .
then I loosing overview and forget all this print_r in different files, so I looked for a way for easier debugging and I started to glue some helpful available scripts and make them work in phpwcms.
How it looks
What it do
You can output your arrays for control without loosing control, on top of your page, with a toggleswitch on the right top of your page.
For shorter variables (long content will be stripped) and in case you use Firebug debugging Tool for Firefox, you can output your stuff to the Firebug Console.
The Debugging is working just for logged-in administrators or you've set the DEBUG switch (not for Firebug debug - it just depends on admin).
What it require
You need a current phpwcms installation (i've tested on the last snapshot, but earlier versions should work too) and a current mootools.jsfile. make shure you've got them in /template/inc_js/mootools/mootools.js.
Mootools works in every modern browser - I prefer Firefox because of Firebug and all the other Developement Extensions - so I think you use it too.
The Firebug debugging option works only in Firefox with Firebug installed, maybe with Firebug lite (the JS emulation for other browsers).
To get the Firebug things done (means put PHP variables to JavaScript variables) it will use a function json_encode() which is build in in PHP5.x. For PHP 4.x this function is emulated in the provided scriptfile. Delete, comment out or rename the function if you work with PHP 5.x and/or an error appears that the function json_encode() can not redeclared.
How it works
It use mootools to add HTML Elements and provide some slidein/slide out fancy. without mootools, nothing will display. So you keep your sourcecode clean - the debugoutput will only generated by javascript.
No changes anywhere in your phpwcms installation - the script holds all Javascript (exept mootools.js and CSS
1. you can output variables and structures with the following snippets somewhere in your code
Code: Select all
# use
$moDebug['all_content_vars'] = print_r($content,TRUE);
# or inside functions
$GLOBALS['moDebug']['vars_from_function'] = $var;
Code: Select all
ob_start();
var_dump($GLOBALS['content']['struct']);
$moDebug['content_struct'] = ob_get_contents();
ob_end_clean();
2. you can output smaller arrays to the Firebug Console with this:
Code: Select all
# use
$FBdebug['_session'] = $_SESSION;
$FBdebug['_server'] = $_SERVER;
# or inside functions
$GLOBALS['FBdebug']['vars_from_function'] = $var;
Download the attached file and copy it to your /templates/inc_script/frontend_render folder
Keep the filename 999_debug.php because this script should executed as last, to catch all variables anywhere.
To see the effect, write one of the above code somewhere in a frontend_render/ script.
Now you can slidein/out your needed data.
Important
This script is really beta. I think the first trouble will come when mootools is included twice (with lightbox or so) - but I will develop this script at the same time with a current project, so I will fix bugs in future.
This script is teaching myself mootools and all the stuff I still not know - so the code may be lazy or uneffective or unsecure use it at your own risk and post your suggestions or comments here.
I can not give much support to this script - you should basicly know what you do in PHP (else you would not be interested in this "extension" ). The script is commented and should be easy to understand.
But as I said, post your feedback.
Credits
The following resources helped me to get this done:
Styling the output:
http://shiflett.org/blog/2006/oct/forma ... e-listings
Firebug PHP debugging idea and function:
http://forenblogger.de/2006/10/07/entwi ... und-tests/
For php2javascript json_encode() function in PHP 4
http://freshmeat.net/p/upgradephp
Ok, I hope this is useful for someone and save some time while developing nice modules/extensions for PHPwcms.
Greetings marcus