maximebf / php-debugbar

Debug bar for PHP
phpdebugbar.com
MIT License
4.19k stars 400 forks source link

problems setting up php debugbar #198

Open darkweb2015 opened 9 years ago

darkweb2015 commented 9 years ago

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

barryvdh commented 9 years ago

What's the rendered output? And do you have any 404's on the assets?

darkweb2015 commented 9 years ago

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.

darkweb2015 commented 9 years ago

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>