Home >Backend Development >PHP Tutorial >Detailed explanation of how to disable debugging Debug Toolbar on specific pages in Yii2

Detailed explanation of how to disable debugging Debug Toolbar on specific pages in Yii2

巴扎黑
巴扎黑Original
2017-08-10 16:11:191631browse

This article mainly introduces you to the relevant information on how to disable the debug toolbar Debug Toolbar on a specific page in Yii2. The article introduces it in detail through detailed example code, which has certain reference value for everyone's study or work. , friends who need it can come and take a look below.

Preface

This article mainly introduces the relevant content about disabling the debug toolbar Debug Toolbar on a specific page of Yii2, and shares it with everyone. Reference study, not much to say, let’s take a look at the detailed introduction:

yii2’s debugging toolbar is an artifact. As long as it is configured in the configuration file web.php, it can be used globally


// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
 'class' => 'yii\debug\Module',
 // uncomment the following to add your IP if you are not connecting from localhost.
 //'allowedIPs' => ['127.0.0.1', '::1'],
];

But sometimes, in a specific The debugging toolbar needs to be disabled on the page.

Create a new tool class Tools.php


namespace app\libs;

use Yii;

class Tools
{
 public static function DebugToolbarOff()
 {
  if (class_exists('\yii\debug\Module')) {
   Yii::$app->view->off(\yii\web\View::EVENT_END_BODY, [\yii\debug\Module::getInstance(), 'renderToolbar']);
  }
 }
}

Where you need to disable the debugging toolbar, such as an action, call it directly


use app\libs\Tools;

……

public function actionIndex()
{
 Tools::DebugToolbarOff();

 return $this->render('index');
}

The above is the detailed content of Detailed explanation of how to disable debugging Debug Toolbar on specific pages in Yii2. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn