[moDebug] beta – Debugging-Mod for phpwcms development

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
Post Reply
User avatar
marcus@localhorst
Posts: 815
Joined: Fri 28. May 2004, 11:31
Location: localhorst
Contact:

[moDebug] beta – Debugging-Mod for phpwcms development

Post by marcus@localhorst »

Hi there,
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)
somewhere inside your code and you see which data is available.
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
Image

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;
if you prefer var_dump() to see datatypes you can use it in this style

Code: Select all

ob_start();
	var_dump($GLOBALS['content']['struct']);
  $moDebug['content_struct'] = ob_get_contents();
	ob_end_clean();
it's not nice, but it works.

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;
How to install
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
999_debug.php.zip
download, unzip and place it in your frontend_render folder
(5.78 KiB) Downloaded 223 times
User avatar
update
Moderator
Posts: 6455
Joined: Mon 10. Jan 2005, 17:29
Location: germany / outdoor

Re: [moDebug] beta – Debugging-Mod for phpwcms development

Post by update »

This sounds awesome!
you should basicly know what you do
Don't know ;) but I am trying to learn :lol: - (hopefully) this can be of some help for me doing so...
It's mostly all about maintaining two or three customer's sites Still supporter for the band Mykket Morton. Visit Mykket Morton on FB. Listen Mykket Morton and live videos on youtube.
Now building a venue for young artists to get wet on stage, rehearsal rooms, a studio, a guitar shop - yes I'm going to build some guitars.
User avatar
Jensensen
Posts: 3000
Joined: Tue 17. Oct 2006, 21:11
Location: auf der mlauer

Re: [moDebug] beta – Debugging-Mod for phpwcms development

Post by Jensensen »

x
Last edited by Jensensen on Fri 19. Sep 2008, 19:16, edited 1 time in total.
{so_much} | Knick-Knack. | GitHub
Umlaute im URL sind meistens immer Kacke.
User avatar
Oliver Georgi
Site Admin
Posts: 9892
Joined: Fri 3. Oct 2003, 22:22
Contact:

Re: [moDebug] beta – Debugging-Mod for phpwcms development

Post by Oliver Georgi »

There is another default "debugging" output. Just use:

Code: Select all

// echo directly
dumpVar($myVar);

// put result in a var
$mydump = dumpVar($myVar, 2);
Oliver
Oliver Georgi | phpwcms Developer | GitHub | LinkedIn | Систрон
nebenaube
Posts: 139
Joined: Fri 23. Nov 2007, 20:39
Location: Redlands, CA
Contact:

Re: [moDebug] beta – Debugging-Mod for phpwcms development

Post by nebenaube »

If you are working on localhost with a standalone installation of everything you can turn on the error reporting in php.ini as well.
Post Reply