How can I disable yii-debug-toolbar on a specific view?
Asked Answered
P

10

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.

Plasticizer answered 9/5, 2014 at 8:46 Comment(4)
Any chance you would consider updating your accepted answer, bearing in mind the up votes and down votes?Priggish
Thanks! I hope you find my answer useful in your own coding with Yii.Priggish
I've already given up PHP and changed to NodeJS ;)Plasticizer
Good luck with that. However, if I may give advice - never "give up" a language, they all have their place!Priggish
P
45

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().

Priggish answered 6/3, 2015 at 17:11 Comment(5)
OMG that totally worked! That is not at all obvious! You must have looked at the source to find it!Evade
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.Priggish
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.Isreal
@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.Priggish
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']);Britska
T
12

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

$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = 'yii\debug\Module';
Tammietammuz answered 31/12, 2014 at 7:57 Comment(1)
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.Priggish
I
7

I found a better way. Put This In Anywhere:

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

And this does not make files in /runtime/debug

Intended answered 20/11, 2016 at 9:45 Comment(1)
This caused some php errors on my page.Tierell
B
6
public function beforeAction($action) {

    if ( $action->controller->id=='elfinder' && Yii::$app->getModule('debug') )
        Yii::$app->getModule('debug')->instance->allowedIPs = [];
    return parent::beforeAction($action);
}
Blum answered 4/6, 2015 at 7:3 Comment(0)
C
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.

Complaisance answered 14/7, 2016 at 7:32 Comment(0)
A
0

Open the file Your-Project-Name\vendor\yiisoft\yii2-debug\src\assets\js\toolbar.js.

Change line toolbarEl.style.display = 'block'; to toolbarEl.style.display = 'none';

Abscess answered 25/12, 2021 at 8:34 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Guffey
M
0

To stop collection log data in a single action or all actions in a single controller I did this and it brought down the memory footprint significantly.

public function beforeAction($action)
{
    if (YII_DEBUG && Yii::$app->getModule('debug'))
    {
        foreach (Yii::$app->getModule('debug')->get('log')->targets as $Target)
        {
            $Target->enabled = false;
        }

        // If you are using Yii framework version >= 2.0.14 you may also
        // want to disable the event registered by EventPanel because it
        // could also use a lot of memory.
        \yii\base\Event::off('*', '*');
    }

    return parent::beforeAction($action);
}
Morph answered 18/10, 2022 at 7:32 Comment(0)
G
-1

Remove this from config/web.php

$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = 'yii\debug\Module';
Graphic answered 25/1, 2018 at 13:41 Comment(0)
S
-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.

Statistical answered 25/8, 2018 at 15:51 Comment(4)
This will enable debug module.Naoma
i mean to comment it out sorry.Statistical
There are already three exact the same answers. There is no need to post the same solution multiple times.Naoma
i was not allowed to upvote that status that was why i had to state that it worked and that explained that it worked for me.Statistical
R
-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.

Recumbent answered 9/5, 2014 at 9:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.