Search code examples
phpyii2yii2-advanced-appyii2-basic-app

Yii2 Debugbar is not showing the file line


I am trying to see the traceLine on Yii2 debug bar like explains in (https://github.com/yiisoft/yii2-debug#open-files-in-ide), but I can't see it.
I have Yii2 2.0.28 and debug-bar 2.1.9 with php 7.2.19
For example: is there any way, inspecting any debug bar’s panel, to know which line of my code thrown a trace/profile action in the debug bar?
Or how can I see where is located any query I am seeing in the database panel?

My config:

$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
    'class' => 'yii\debug\Module',
    'traceLine' => '<a href="phpstorm://open?url={file}&line={line}">{file}:{line}</a>',
    'allowedIPs' => ['*'],
    'panels' => [
        'db' => [
            'class' => 'yii\debug\panels\DbPanel',
            'defaultOrder' => [
                'seq' => SORT_ASC
            ],
            'defaultFilter' => [
                'type' => 'SELECT'
            ]
        ],
    ],
];

Solution

  • There are two properties in configuration that affect how the files are displayed in logs in debug bar.

    1) traceLine property of debug module. This property contains a template for displaying single line of trace. In configuration it may look like this

    $config['modules']['debug'] = [
        'class' => 'yii\debug\Module',
        'traceLine' => '<a href="phpstorm://open?url={file}&line={line}">{file}:{line}</a>',
        // ... other debug module configurations
    ]
    

    2) traceLevel property of log component. This affect how many calls will be displayed in trace. The calls of framework's classes are not displayed in debug toolbar, only your files are displayed. The configuration might look like this

    'components' => [
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            // ... other log component configurations
        ],
        // ... other components
    ],
    

    In the example the traceLevel depends on YII_DEBUG constant. This is used to avoid performance issues in production environments. This is also how traceLevel is set in default yii2 application templates.

    The YII_DEBUG constant is usually set in index.php file like this

    defined('YII_DEBUG') or define('YII_DEBUG', true);