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

ThinkPHP中SHOW_RUN_TIME不能正常显示运行时间的解决方法 原创

程序员文章站 2022-10-11 12:43:28
本文实例讲述了thinkphp中show_run_time不能正常显示运行时间的解决方法。分享给大家供大家参考。具体如下: 在thinkphp的config.php中设置...

本文实例讲述了thinkphp中show_run_time不能正常显示运行时间的解决方法。分享给大家供大家参考。具体如下:

在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__}'))
 {
  $runtime = c('show_run_time')? ''.$this->showtime().'' : '';
  $content = str_replace('{__runtime__}', $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,'{__runtime__}'))
 {
  $content = str_replace('{__runtime__}', $runtime, $content);
 }
 else
  $content .= $runtime;
 echo $content;
 if(c('show_page_trace')) $this->showtrace();
 return null;
}else {
 return $content;
}

至此问题搞定!

更多关于thinkphp相关内容感兴趣的读者可查看本站专题:《thinkphp入门教程》及《thinkphp常用方法总结

希望本文所述对大家基于thinkphp框架的php程序设计有所帮助。