CodeIgniter 4 Database Debug Toolbar Query Highlighter.
- Requirement
- Installation
- Configuration (Optional)
- ScreenShot
- Credit
Install library via composer:
composer require nfaiz/dbtoolbar
Query Highlighter is located at DbQueries tab (Debug Toolbar)
- Open and comment
Database::class
from$collectors
property inapp/Config/Toolbar.php
.
public array $collectors = [
// Database::class,
];
- Open and comment
Events::on('DBQuery', 'CodeIgniter\Debug\Toolbar\Collectors\Database::collect');
inapp/Config/Events.php
.
if (CI_DEBUG && ! is_cli()) {
// Events::on('DBQuery', 'CodeIgniter\Debug\Toolbar\Collectors\Database::collect');
Services::toolbar()->respond();
}
Open and add properties below in app/Config/Toolbar.php
accordingly.
/**
* -------------------------------------------------------------
* Disable DbToolbar query Highlighter
* -------------------------------------------------------------
*
* To disable DbToolbar query highlighter, change value to true
*
* @var bool
*/
public bool $dbToolbarDisable = false;
/**
* -------------------------------------------------------------
* DbToolbar Theme
* -------------------------------------------------------------
*
* Configuration for light and dark mode SQL Syntax Highlighter.
* Refer https://github.com/scrivo/highlight.php/tree/master/src/Highlight/styles or
* use \HighlightUtilities\getAvailableStyleSheets(); for available stylesheets.
*
* @var array
*/
public array $dbToolbarTheme = [
'light' => 'atom-one-light',
'dark' => 'atom-one-dark'
];
/**
* -------------------------------------------------------------
* DbToolbar View
* -------------------------------------------------------------
*
* To override DbToolbar SQL Syntax Highlighter view.
*
* @var array
*/
public string $dbToolbarTpl = 'Nfaiz\DbToolbar\Views\database.tpl';
/**
* -------------------------------------------------------------
* Bottom Margin Between Diplayed Query in Toolbar
* -------------------------------------------------------------
*
* Value in px
*
* @var int
*/
public int $dbToolbarMarginBottom = 4;
/**
* -------------------------------------------------------------
* Log Queries
* -------------------------------------------------------------
*
* Please set threshold to minimum 7 at app/Config/Logger.php
* Logs can be found at ROOTPATH/writable/logs
*
* @var boolean
*/
public bool $dbToolbarLogger = false;
Open app/Config/Toolbar.php
and add/edit template view file using $dbToolbarTpl
property.
You can create your own view and you change it accordingly. For Example public $dbToolbarTpl = dbtoolbar/database;
Views/dbtoolbar/database.php.
{! hlstyle !}
<table>
<thead>
<tr>
<th class="debug-bar-width6r">Time</th>
<th>Query String</th>
</tr>
</thead>
<tbody>
{queries}
<tr class="{class}" title="{hover}" data-toggle="{qid}-trace">
<td class="narrow" style="vertical-align: top;">{duration}</td>
<td><u>{trace-file}</u>{! sql !}</td>
</tr>
<tr class="muted debug-bar-ndisplay" id="{qid}-trace">
<td></td>
<td>
{trace}
{index}<strong>{file}</strong><br/>
{function}<br/><br/>
{/trace}
</td>
</tr>
{/queries}
</tbody>
</table>
- Light
- Dark
- Light
- Dark
- Inspired by this pull request