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 , 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']); } } }
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'); }
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!