yii2的調試工具欄,堪稱神器。在配置文件web.php中配置好,就能全局使用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'], ];
可是有的時候,在特定頁面中須要禁用調試工具欄。web
新建工具類Tools.phpbootstrap
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,直接調用yii2
use app\libs\Tools; …… public function actionIndex() { Tools::DebugToolbarOff(); return $this->render('index'); }