当前位置: 移动技术网 > IT编程>开发语言>PHP > 在Yii2特定页面如何禁用调试工具栏Debug Toolbar详解

在Yii2特定页面如何禁用调试工具栏Debug Toolbar详解

2017年12月12日  | 移动技术网IT编程  | 我要评论

前言

本文主要给大家介绍了关于在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');
}

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对移动技术网的支持。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网