Yii2 在特定页面中禁用调试工具栏Debug Toolbar
yii2的调试工具栏,堪称神器。在配置文件web.php中配置好,就能全局使用
// 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'], ];
但是有的时候,在特定页面中需要禁用调试工具栏。
新建工具类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']); } } }
在需要禁用调试工具栏的地方,如某个action,直接调用
use app\libs\Tools; …… public function actionIndex() { Tools::DebugToolbarOff(); return $this->render('index'); }
相关推荐
WasteLand 2020-10-18
Allinputs 2020-08-30
Ashes 2020-06-14
caiyiii 2020-06-14
kxguan 2020-06-14
daillo 2020-06-14
一粒沙里的世界 2020-06-14
ruxingli 2020-06-14
csssy00 2020-06-14
阿佐 2020-06-14
NameWFY 2020-05-28
NameWFY 2020-05-26
Robin罗兵 2020-05-16
caiyiii 2020-04-29
wmsjlihuan 2020-04-26
cbao 2020-04-26
csssy00 2020-04-19
igogo00 2020-03-09