Home > Backend Development > PHP Tutorial > Detailed explanation of how to disable the debug toolbar Debug Toolbar on a specific page in Yii2

Detailed explanation of how to disable the debug toolbar Debug Toolbar on a specific page in Yii2

不言
Release: 2023-03-29 14:20:02
Original
1293 people have browsed it

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'],
];
Copy after login

But sometimes , the debug toolbar needs to be disabled in specific pages.

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']);
  }
 }
}
Copy after login

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

use app\libs\Tools;

……

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

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

Related recommendations:

Yii2 uses database operation summary (add, delete, check, modify, transaction)

Usage of yii2 multi-image upload component

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template