本文實例講述了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框架的php程序設計有所幫助。