php-debugbar
php-debugbar copied to clipboard
problems setting up php debugbar
Hi,
I am trying to implement PhpDebugBar on a simple index.php page. The code below shows what I have:
<?php
require('vendor/autoload.php');
use DebugBar\StandardDebugBar;
$debugbar = new StandardDebugBar();
$debugbarRenderer = $debugbar->getJavascriptRenderer(false)
->setBaseUrl('/testproj/assets')
->setEnableJqueryNoConflict(false);
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<?php echo $debugbarRenderer->renderHead() ?>
<script type="text/javascript">
$(function() {
$('.ajax').click(function() {
var container = $(this).parent().html('...');
$.get(this.href, function(data) {
container.html(data);
});
return false;
});
});
</script>
</head>
<body>
<?php echo $debugbarRenderer->render(false) ?>
</body>
</html>
Every thing loads fine but the debugbar itself is a no show. The error I get is
Uncaught ReferenceError: phpdebugbar is not defined
Any chance anyone can help me with this problem? Thanks
What's the rendered output? And do you have any 404's on the assets?
Hi Barry,
There are no 404s on the assets at all. In chrome, I am able to click on each asset and view its contents.
When I manually add the following code just above the line that renders the bar itself, the debugbar shows up and the javascript error is gone:
<script>
var phpdebugbar = new PhpDebugBar.DebugBar();
phpdebugbar.createTab("messages", new PhpDebugBar.Widgets.MessagesWidget());
phpdebugbar.createTab("request", new PhpDebugBar.Widgets.VariableListWidget());
phpdebugbar.createIndicator("time", "time", "Request Duration");
phpdebugbar.createTab("timeline", new PhpDebugBar.Widgets.TimelineWidget());
phpdebugbar.createIndicator("memory", "cogs", "Memory Usage");
phpdebugbar.createTab("exceptions", new PhpDebugBar.Widgets.ExceptionsWidget());
//phpdebugbar.createTab("database", new PhpDebugBar.Widgets.SQLQueriesWidget());
phpdebugbar.setDataMap({
"messages": ["messages.messages", []],
"messages:badge": ["messages.count", null],
"request": ["request", {}],
"time": ["time.duration_str", '0ms'],
"timeline": ["time", {}],
"memory": ["memory.peak_usage_str", '0B'],
"exceptions": ["exceptions.exceptions", []],
"exceptions:badge": ["exceptions.count", null]
//"database": ["pdo", []],
//"database:badge": ["pdo.nb_statements", 0]
});
phpdebugbar.restoreState();
</script>