前言
本文主要给大家介绍了关于在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');
}
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对硕编程的支持。
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!