前言
本文主要给大家介绍了关于在Yii2特定页面禁用调试工具栏Debug Toolbar的相关内容,分享出来供大家参考学习,话不多说了,来一起看看详细的介绍:
yii2的调试工具栏,堪称神器。只要在配置文件web.php中配置好,就能全局使用
// configuration adjustments for 'dev' environment $config['bootstrap'][] = 'debug'; $config['modules']['debug'] = [ 'class' => 'yiidebugModule', // uncomment the following to add your IP if you are not connecting from localhost. //'allowedIPs' => ['127.0.0.1', '::1'], ];
但是有的时候,在特定页面中需要禁用调试工具栏。
新建工具类Tools.php
namespace applibs;
use Yii;
class Tools
{
public static function DebugToolbarOff()
{
if (class_exists('yiidebugModule')) {
Yii::$app->view->off(yiiwebView::EVENT_END_BODY, [yiidebugModule::getInstance(), 'renderToolbar']);
}
}
}在需要禁用调试工具栏的地方,如某个action,直接调用
use applibsTools;
……
public function actionIndex()
{
Tools::DebugToolbarOff();
return $this->render('index');
}| 欢迎光临 一起源码网 (https://www.171739.xyz/) | Powered by Discuz! X3.3 |