18

How can I disable yii-debug-toolbar on a specific view especially on partial rendered views?

Is this possible?

p.s. Yii-debug-toolbar does unfortunately not exist as a tag below.

zishe
  • 10,055
  • 12
  • 60
  • 101
Lonely
  • 5,174
  • 6
  • 33
  • 67

8 Answers8

44

Put this in your layout or view file:

if (class_exists('yii\debug\Module')) {
    $this->off(\yii\web\View::EVENT_END_BODY, [\yii\debug\Module::getInstance(), 'renderToolbar']);
}

This removes the callback that renders the toolbar from the event that runs at the end of the layout, where you have $this->endBody().

spikyjt
  • 1,870
  • 19
  • 16
  • OMG that totally worked! That is not at all obvious! You must have looked at the source to find it! – Chloe Apr 10 '15 at 03:42
  • 1
    I just updated this to check if you are in debug mode, because in live mode you probably don't have the yii-debug module installed and it will throw an error without this catch. – spikyjt Jun 30 '15 at 13:51
  • I suppose this is the condition used when the debugging is on, but we just want to disable the toolbar for a specific view or entire layout. – shasi kanth Aug 27 '15 at 09:27
  • 1
    @shasikanth I'm saying, add this in your view or layout, then it will disable it. The test is just so that is doesn't try to remove the event handler if the debug module isn't even there, i.e. in production. I've just done another edit to improve the test. – spikyjt Aug 28 '15 at 08:41
  • 1
    this doesn't work in the controller code and only when in a view/layout. For controller usage: Yii::$app->getView()->off(\yii\web\View::EVENT_END_BODY, [\yii\debug\Module::getInstance(), 'renderToolbar']); – BHoft Feb 19 '18 at 14:40
12

Just Remove or comments out the those two lines from /config/web.php

$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = 'yii\debug\Module';
zisoft
  • 21,200
  • 10
  • 56
  • 72
Tanvir Rahman
  • 145
  • 1
  • 4
  • 5
    This doesn't answer the question. The OP wanted to know how to disable the debug toolbar only in a specific view, whilst keeping it enabled in other views. Following this answer disables it completely. – spikyjt Mar 06 '15 at 16:03
6
public function beforeAction($action) {

    if ( $action->controller->id=='elfinder' && Yii::$app->getModule('debug') )
        Yii::$app->getModule('debug')->instance->allowedIPs = [];
    return parent::beforeAction($action);
}
Sport
  • 6,972
  • 6
  • 38
  • 61
Goodini
  • 61
  • 1
  • 1
6

I found a better way. Put This In Anywhere:

Yii::$app->log->targets['debug'] = null;

And this does not make files in /runtime/debug

Zneiat
  • 61
  • 1
  • 2
0

if you want to remove from front end then this is the way:

  1. Goto frontend/config/main-local.php
  2. Comment out these two lines:

main-local.php

  $config['bootstrap'][] = 'debug';    
  $config['modules']['debug'] = 'yii\debug\Module';

This will remove debug bar from front-end.

Skatox
  • 3,919
  • 10
  • 39
  • 42
Umair Hamid
  • 3,040
  • 2
  • 18
  • 24
-1

Remove this from config/web.php

$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = 'yii\debug\Module';
Sapna
  • 1
  • 1
-1
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = 'yii\debug\Module';

Comment out the above lines of code above. this worked for me. This do in frontend and backend to disable that debug tool or module at the footer of the website.

-7

If you don't wan to show the log, you can hide the yii-debug console using jQuery

   $('#ydtb-toolbar').hide();

Call this snippet on your views.

Hearaman
  • 7,509
  • 12
  • 36
  • 53