Detailed introduction to using the open source DebugBar tool to debug PHP code (pictures and texts)

黄舟
Release: 2023-03-06 18:18:02
Original
2439 people have browsed it

DebugBar is a free and open source application that can be integrated into any PHP project and collect and display analysis data.
Does it have any dependencies? It supports Ajax requests, including general data collectors and collectors of commonly used development libraries.

I believe that students who have used Laravel's debugging tool feel that this tool is very powerful and easy to use, which greatly improves the productivity of programmers. In fact, Laravel is the tool It is upgraded from the open source php-debugbar.

Detailed introduction to using the open source DebugBar tool to debug PHP code (pictures and texts)

How can we use this native php-debugbar debugging tool in other platforms frameworks?

Detailed introduction to using the open source DebugBar tool to debug PHP code (pictures and texts)

Detailed introduction to using the open source DebugBar tool to debug PHP code (pictures and texts)

This debugging is managed using the composer package. Let’s go to Github first. See how to use:
maximebf/php-debugbar

Usage

1. Download package

composer require maximebf/debugbar
Copy after login

2. Specific usage

<?php

// Require the Composer autoloader, if not already loaded
require &#39;vendor/autoload.php&#39;;

use DebugBar\StandardDebugBar;

$debugbar = new StandardDebugBar();
$debugbarRenderer = $debugbar->getJavascriptRenderer();

$debugbar["messages"]->addMessage("hello world!");
?>
<html>
    <head>
        <?php echo $debugbarRenderer->renderHead() ?>
    </head>
    <body>
        ...
        <?php echo $debugbarRenderer->render() ?>
    </body>
</html>
Copy after login

3.staticHandling of resource not loading problem

Detailed introduction to using the open source DebugBar tool to debug PHP code (pictures and texts)

When using, if the static resource of the package is not loaded, the source code needs to be modified, because the source code is static The resource path cannot be found in the local server. The root URL of the source code uses a relative path under the server, such as: http://localhost/vendor/maximebf/debugbar/src/DebugBar/ResourcThis path , and our package is placed in a directory like http://localhost/web/php-debugbar/vendor/maximebf/debugbar/src/DebugBar/Resourc under the server, so we need to JavascriptRenderer.php The $baseUrl of the file variable is modified:

The location of the file:

vendor/maximebf/debugbar/src/DebugBar/JavascriptRenderer.php
Copy after login
// 原来的
$baseUrl = &#39;/vendor/maximebf/debugbar/src/DebugBar/Resources&#39;;

// 修改后的,只加了一个表示当前路径的点 "."
$baseUrl = &#39;./vendor/maximebf/debugbar/src/DebugBar/Resources&#39;;
Copy after login

Detailed introduction to using the open source DebugBar tool to debug PHP code (pictures and texts)

The above is the detailed content of Detailed introduction to using the open source DebugBar tool to debug PHP code (pictures and texts). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!