A PHP Developer's Blog - Joakim Nygård

About jokke.dk

jokke.dk is the personal website of , a software architect, entrepeneur and Mac user living in Copenhagen, Denmark. Read more »

Search the Site

Recent Posts

Popular Posts

Introducing the Scienta ZF Debug Bar

7th January, 2009  |  44 Comments

Update: There's a new blog post with details on version 1.4.

Since the early betas I've been using the Zend Framework in several professional and personal PHP projects with great joy. To aid the development process, I decided to build an easy to use debug panel. This first version requires the Zend MVC paradigm as it is implemented as a Zend_Controller_Plugin.

The Scienta ZF Debug Bar injects into every request a snippet of HTML with commonly used debug information. Time spent, memory usage and number of database queries are presented at a glance. Additionally, included files, a listing of available view variables and the complete SQL command of all queries are shown in separate panels. Combined, I believe it can cut down on the number of debug output statements like var_dump while developing - I know it did for me.

The output is a simple bar in the lower left corner of the browser window:

2009 Scienta Debug Bar

Clicking each of the sections short of the memory display will bring up a panel with more information:

To install, place the folder 'Scienta' in your library path, next to the Zend folder. Then add the following lines to your bootstrap file:

$scBar = new Scienta_Controller_Plugin_Debug(array(
            'database_adapter' => $db, // Zend_Db_Adapter_Abstract
            'memory_usage' => true,
            'collect_view_vars' => true));
$frontController = Zend_Controller_Front::getInstance();
$frontController->registerPlugin($scBar);

The constructor options array is optional and allows for disabling specific panels, e.g. if no database adapter is presented, the query section and panel will not be shown. More info and download Scienta ZF Debug Bar here.

This release is the first public version. As such there is surely bugs and clever features missing. Never the less, I hope it will make for a somewhat faster development process - let me know.

Update As several readers have pointed out, the look of Scienta Debug Bar is very similar to the Symfony Framework. The icons are from the excellent Silk Set by Mark James - also used by Symfony.

« One Application to Rule Your Files  –  A New Look »

44 Comments

ask

8th January, 2009

Superfedt :) glæder mig til at kigge nærmere på den.

Jeg ku' forestille mig en option så debuginfo bare blev outputtet til FireBug (ligesom FirePHP) ville være smart.


[MA]Pascal

8th January, 2009

No credits to original author ?


NiKo

8th January, 2009

Reminds me somthing symfony-related... anyway, that's a nice feature


Michel Bertier

8th January, 2009

nice work, would have been nice to credit appropriate people though...

django people seem to be more polite than ZF coders :P

http://rob.cogit8.org/blog/2008/Sep/19/introducing-django-debug-toolbar/


Stefan

8th January, 2009

Good to see the symfony toolbar making it to Zend Framework!


Joshua May

8th January, 2009

That's definitely something I know a lot of developers (in other languages, too) would like to see, and have been somewhat jealous of symfony for a while now!

Nice to see someone doing something productive with it.

Credit, of course, where credit is due though..


Eric

12th January, 2009

Definitively a VERY nice feature !

Maybe it could be improved in some way :
* Add controllers timings (via preDispatch/postDispatch)
* Plugable output (FireBug, plain html, ...)

I also hope it will find is way in Zend Framework core :)

Thanks for it !


eMeRiKa

7th February, 2009

Thanks you !

It is possible to use two database_adapters with your debug bar ?


M4d3L

11th February, 2009

Very nice tool. I will integrate to my work.

any possibility to add easy positionning config?

where we can config an array like

array(
'top' = '5px',
'bottom' = '',
'left' = '',
'right' ='5px'
)

so this will put the bar in the top right


M4d3L

19th February, 2009

Nice I just have try your last version. it is more fast now. I want to include your work as an official plugin of my new Portal system build on ZF. I some idea for this plugin. Like to catch Firephp information send to client for who making test in IE or other navigator that doesnt have firebug plugin installed like on Safari Iphone.

You will find here information about my portal system here - http://code.google.com/p/phenixzps/
Am working on cleaning the code and add comment then I will release the experimental code.



dizi izle

21st February, 2009

Nice Write Thank You mate.. i think i will like this site.

dizi izle
dizi seyret


umpirsky

30th March, 2009

Nice job!

TODO:

Make debug bar XHTML valid (this is important)
Use self:: instead className::


Hugo

30th March, 2009

Nice symfony feature :)


gabriel solomon

30th March, 2009

hello,

a very cool plugin. But i have a little bug with it :(
it crashes my prototype scripts :(


Keith

30th March, 2009

Hey there, I tried running it on my site and got a really wacky error. If I view source, I see this line:



If I view compiled source (FF web dev toolbar) I see this:

<style type=" text="" css="" media="screen"

Looked into it for a few minutes, but didn't see anything out of the ordinary. No idea what's doing that. Guesses?


Gerard Roche

31st March, 2009

Very nice, two suggestions:

1. An Included files count

Included files ({COUNT})
... files included ...
... files included ...


And

2.

Add a pointer to the cursor in CSS when hovering on action buttons http://reference.sitepoint.com/css/cursor.



Gerard Roche

31st March, 2009

@umpirsky

I agree, this is very important.

XHTML STRICT valid.


Joakim Nygård

31st March, 2009

Thanks for all your feedback :)

The plugin output should definitely validate. There are however many problems with XHTML, particularly that IE does not support files transfered as application/xhtml+xml. Transfering as text/html is allowed but will not trigger any xml wellformed checks.

Also see http://codinginparadise.org/weblog/2005/08/xhtml-considered-harmful.html

The next version will be HTML4 Strict valid.

I will also add the suggested pointer cursor and a count on included files. The new version should be ready in a few days.


Jonathan Persson

31st March, 2009

Really nice! Thanks!


Nicolas H

1st April, 2009

Nice and useful!

Note that the "view vars" functionality uses the "getVars()" method of the view object, which is not present in the Zend_View_Interface. So, if you use an alternate template engine (like explained in http://framework.zend.com/manual/en/zend.view.scripts.html#zend.view.scripts.templates.interface), you have to add the "getVars" method.

For example, with smarty :

class Class_View_Html extends Smarty implements Zend_View_Interface {
...
public function getVars() {
return $this-get_template_vars();
}
}


Kaffee

2nd April, 2009

How about support for $_COOKIE, $_SESSION, DOM-Elements (document.getElementsByTagName("*").length) and code execution coverage (with xdebug)? :)


alberto

2nd April, 2009

anyone has some ideas to use sql debug using doctrine?


Ben

2nd April, 2009

Added Doctrine support:
http://php.pastebin.ca/raw/1379134


alberto

3rd April, 2009

Thanks Ben


darookee

26th April, 2009

Added Zend_Registry memory usage display when clicking on the memory tab:
http://rafb.net/p/6jH6sH67.html


Jurian Sluiman

12th May, 2009

I have altered the debug bar. The constructor calls now the public method setOptions(). This method contains the constructor contents except for the timer. On request I can send you the patch.

Now it is possible to load the debug bar with your application.ini. Anywhere you want to setup the options (for me, the database_adapter) it is possible to do it elsewhere. The application.ini has no possibility to add these options, so I bootstrap them with the new setOptions() method. The control of enabling the plugin stays nevertheless in my application.ini.


Paul Parenko

18th May, 2009

$options = array(
'database_adapter' = $this-getPluginResource('db')-getDbAdapter(), // or array of adapters
'memory_usage' = TRUE, // default value shown
'collect_view_vars' = TRUE,
'sort_view_vars' = TRUE,
'show_exceptions' = TRUE,
'handle_errors' = FALSE,
'execute_tests' = TRUE,
'tests_path' = array(APPLICATION_PATH.'../tests'),
'tests_list' = array('BootstrapTest'),
'tests_place' = array('controller' = 'Index',
'action' = 'Index',
'test' = 'on'),
);

$scBar = new Septem_Controller_Plugin_Debug($options);
$frontController = Zend_Controller_Front::getInstance();
$frontController-registerPlugin($scBar);


Paul Parenko

18th May, 2009

Sorry but I forgot the text:
How about showing tests (PHPUnit) if they are successful or not with Scienta ZF Debug Bar?
And the options could contain the path to the unit-tests (or many in an array), permission to make tests, the place where the tests should be execute.

i.e. see upper


Phillip Winn

19th May, 2009

I really, really, really don't get how anybody has DB stuff this early in the startup. People configure their DB adapters before even dispatching to the front controller? Really?


Joakim Nygård

20th May, 2009

@Phillip Winn:

The latest version in svn (v1.5) has been rewritten to allow easier customization.
With this it is possible to load plugins after the ZFDebug bar has been registered with the front controller.

$zfdebug = Zend_Controller_Front::getInstance()->getPlugin('ZFDebug_Controller_Plugin_Debug');
$zfdebug-registerPlugin(new ZFDebug_Controller_Plugin_Debug_Plugin_Database($optionsArray));

This can be done at any point before dispatchLoopShutdown().


SLIM

3rd July, 2009

ZFDebug\Controller\Plugin\Debug.php
[php]
protected function _output($html)
{
$response = $this-getResponse();
$response-prependBody($this-_headerOutput() . ''.$html.'');
}
[/php]
and add options (append or prepend)

it's will be likely


SLIM

3rd July, 2009

sorry the site cut meny tags, but i hope that your understand my fix


a?k mesajlar?

17th July, 2009

Thanks you !

It is possible to use two database_adapters with your debug bar ?


ask mesajlari

17th July, 2009

Thanks you !

It is possible to use two database_adapters with your debug bar ?


Joakim Nygård

17th July, 2009

Hi,

It is indeed possible to use two database adapters. Just pass them as an array like so:

[...]
'database_adapter' = array('adapter' = array($db1, $db2))
[...]


lazer epilasyon

10th September, 2009

Do you have some example code?


sesli siirler

9th October, 2009

anyone has some ideas to use sql debug using doctrine?


Snowcore

3rd December, 2009

Thats really useful plugin! Thanks!
Now I am using it in all of my projects :)


Cialis

18th December, 2009

When I open your site in your browser, Safari 4 in Mac OS X, some elements of the page and off to the side and the text is broken: ( Please help me How can I remove the problem?


john

30th January, 2010

Teak Shower BenchTeak Shower BenchTeak Shower Bench
Teak Shower Bench
Teak Shower Bench
Teak Shower Bench
Teak Shower Bench
Teak Shower Bench
Teak Shower Bench
Teak Shower Bench
Teak Shower Bench
Teak Shower Bench
Teak Shower Bench
Teak Shower Bench
Teak Shower Bench
Teak Shower Bench



zoo coupons

30th January, 2010

great info thx


dizi izle

1st February, 2010

because of your service thank you very much I wish you continued success.


yabanci film izle

8th February, 2010

thank you open your site in


dizi izle

8th February, 2010

thank you very much


Post A Comment

You need JavaScript to post comments.