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:

Clicking each of the sections short of the memory display will bring up a panel with more information:
- Current ZF version. Clicking will display Scienta Debug Bar version and copyright.
- View vars displays a panel with variables available to the view script
- Database queries and time. The panel shows complete SQL commands ready for copy-paste for tweaking
- Time to process the request from
$_SERVER['REQUEST_TIME'] to the Zend_Controller method dispatchLoopShutdown() is called. A click shows included files
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 »
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.
No credits to original author ?
Reminds me somthing symfony-related... anyway, that's a nice feature
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/
Good to see the symfony toolbar making it to Zend Framework!
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..
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 !
Thanks you !
It is possible to use two database_adapters with your debug bar ?
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
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.
Nice Write Thank You mate.. i think i will like this site.
dizi izle
dizi seyret
Nice job!
TODO:
Make debug bar XHTML valid (this is important)
Use self:: instead className::
hello,
a very cool plugin. But i have a little bug with it :(
it crashes my prototype scripts :(
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?
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.
@umpirsky
I agree, this is very important.
XHTML STRICT valid.
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.
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();
}
}
How about support for $_COOKIE, $_SESSION, DOM-Elements (document.getElementsByTagName("*").length) and code execution coverage (with xdebug)? :)
anyone has some ideas to use sql debug using doctrine?
Added Doctrine support:
http://php.pastebin.ca/raw/1379134
Added Zend_Registry memory usage display when clicking on the memory tab:
http://rafb.net/p/6jH6sH67.html
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.
$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);
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
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?
@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().
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
sorry the site cut meny tags, but i hope that your understand my fix
Thanks you !
It is possible to use two database_adapters with your debug bar ?
Thanks you !
It is possible to use two database_adapters with your debug bar ?
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))
[...]
Do you have some example code?
anyone has some ideas to use sql debug using doctrine?
Thats really useful plugin! Thanks!
Now I am using it in all of my projects :)
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?
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
because of your service thank you very much I wish you continued success.
thank you open your site in
Post A Comment
You need JavaScript to post comments.