欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

解决TP中不能正常显示运行时间的方法

程序员文章站 2022-04-08 16:13:50
...
本文主要介绍了ThinkPHP中SHOW_RUN_TIME不能正常显示运行时间的解决方法,针对ThinkPHP配置文件config.php设置SHOW_RUN_TIME后不能显示运行时间情况下的解决方法,涉及针对ThinkPHP底层源文件的修改,需要的朋友可以参考下。希望对大家有所帮助。

具体如下:

在ThinkPHP的config.php中设置:

'SHOW_RUN_TIME'=>true;

可以在模板输出运行时间,但是有的时候会出现不显示运行时间的情况。

对此解决方法如下:

打开 ThinkPHP\Lib\Think\Core\View.class.php文件,
在protected function output($content,$display)方法中
将:

if(C('HTML_CACHE_ON')) HtmlCache::writeHTMLCache($content);
 if($display) {
 if(false !== strpos($content,''))
 {
  $runtime = C('SHOW_RUN_TIME')? ''.$this->showTime().'' : '';
  $content = str_replace('', $runtime, $content);
 }
 echo $content;
 if(C('SHOW_PAGE_TRACE')) $this->showTrace();
 return null;
}else {
 return $content;
}

改为:

if(C('HTML_CACHE_ON')) HtmlCache::writeHTMLCache($content);
 if($display) {
 $runtime = C('SHOW_RUN_TIME')? ''.$this->showTime().'' : '';
 if(false !== strpos($content,''))
 {
  $content = str_replace('', $runtime, $content);
 }
 else
  $content .= $runtime;
 echo $content;
 if(C('SHOW_PAGE_TRACE')) $this->showTrace();
 return null;
}else {
 return $content;
}


相关推荐:

TP5之Auth权限管理实例

thinkphp3.2中替换入口文件

Thinkphp中如何连接分布式数据库

以上就是解决TP中不能正常显示运行时间的方法的详细内容,更多请关注其它相关文章!