yiisoft/yii2-debug
Yii 2 Debug Extension adds a web debugger toolbar and detailed debug pages for your Yii 2 application. Inspect requests, logs, DB queries, profiling data, and more to troubleshoot performance and errors during development.
composer require --prefer-dist yiisoft/yii2-debug
config/web.php:
'bootstrap' => ['debug'],
'modules' => [
'debug' => [
'class' => 'yii\debug\Module',
],
],
Toolbar Integration:
YII_DEBUG = true).panels config (e.g., disable specific panels):
'panels' => [
'db' => ['class' => 'yii\debug\panels\DbPanel'],
'request' => ['class' => 'yii\debug\panels\RequestPanel'],
],
Detailed Debug Pages:
/debug/default/view (or /debug/default for all panels)./debug/default/log-viewer) for granular data.IDE Integration:
traceLine for clickable file/line links:
'traceLine' => '<a href="phpstorm://open?url={file}&line={line}">{file}:{line}</a>',
tracePathMappings:
'tracePathMappings' => [
'/var/www/html' => '/host/path/to/app',
],
Custom Panels:
yii\debug\Panel to collect app-specific metrics (e.g., rendered views, cache hits).ViewsPanel (see docs).Dynamic Panel Loading:
'panels' => YII_ENV_STAGING ? ['db', 'request'] : [],
Event-Driven Debugging:
yii.debug.toolbar_attached in JavaScript:
document.addEventListener('yii.debug.toolbar_attached', (e) => {
const toolbar = e.target;
toolbar.querySelector('.yii-debug-toolbar__block').addEventListener('click', () => {
console.log('Toolbar clicked!');
});
});
Performance Profiling:
profiling panel to measure execution time of specific code blocks:
Yii::$app->profiling->begin('custom_block');
// Code to profile
Yii::$app->profiling->end();
Permission Issues:
@runtime/debug is writable by the web server user.chmod -R 775 runtime/debug (Linux) or adjust Docker volumes.Strict URL Parsing:
enableStrictParsing in urlManager, add:
'rules' => [
'debug/<controller>/<action>' => 'debug/<controller>/<action>',
],
IP Restrictions:
allowedIPs defaults to ['127.0.0.1', '::1']. Add your IP for remote access:
'allowedIPs' => ['192.168.1.100', '127.0.0.1'],
Performance Overhead:
YII_DEBUG = true) slows down requests. Disable in production:
defined('YII_DEBUG') or define('YII_DEBUG', false);
Panel Conflicts:
'panels' => [
'db' => ['class' => 'yii\debug\panels\DbPanel'],
'request' => ['class' => 'yii\debug\panels\RequestPanel'],
],
Toolbar Not Showing:
YII_DEBUG is true and bootstrap includes 'debug'.Database Panel Issues:
db component is configured in components.defaultOrder to sort by execution time:
'panels' => [
'db' => [
'class' => 'yii\debug\panels\DbPanel',
'defaultOrder' => ['duration' => SORT_DESC],
],
],
Custom Panel Data Missing:
save() to return data. Empty returns hide the panel.public function save() {
return $this->_collectedData ?: null;
}
IDE Links Not Working:
'tracePathMappings' => [
'/app' => '/host/path/to/app',
],
file:// URLs first (e.g., ide://open?url=file:///path).Log Viewer Empty:
log component is configured and traceLevel is set:
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [...],
],
Override Panel Templates:
vendor/yiisoft/yii2-debug/views to your app’s views/debug and modify (e.g., panel.php).Modify Summary Output:
getSummary() to change toolbar appearance:
public function getSummary() {
return '<div class="yii-debug-toolbar__block custom-style">' . parent::getSummary() . '</div>';
}
Add Custom CSS/JS:
Yii::$app->view->registerCssFile('@vendor/yiisoft/yii2-debug/web/css/debug.css');
Disable Specific Panels:
'panels' => ['db', '!request'], // Disable 'request' panel
Log Custom Data:
Yii::debug() or Yii::error() to log app-specific data:
Yii::debug(['user_id' => Yii::$app->user->id], 'user-session');
How can I help you explore Laravel packages today?