开启静态缓存以后评论功能报错


最近使用thinkcmf 静态缓存的时候,前台评论的模板地方会报错,仔细查找了下原因,

blob.png

这里定位的路径出错了,定位到了Application下的view文件查找评论模板了,我们的实际comment模版文件应该在themes/simplebootx/comment下。

解决方法:

注释掉自动定位模板文件代码(文件位置Application/Comment/Controller/WidgetController.class.php)。改成这样的

/**
	 * 自动定位模板文件
	 * @access protected
	 * @param string $template 模板文件规则
	 * @return string
	 */
	public function parseTemplate($template='') {
		
		$tmpl_path=C("SP_TMPL_PATH");
		define("SP_TMPL_PATH", $tmpl_path);
		// 获取当前主题名称
		$theme      =    C('SP_DEFAULT_THEME');
		if(C('TMPL_DETECT_THEME')) {// 自动侦测模板主题
			$t = C('VAR_TEMPLATE');
			if (isset($_GET[$t])){
				$theme = $_GET[$t];
			}elseif(cookie('think_template')){
				$theme = cookie('think_template');
			}
			if(!file_exists($tmpl_path."/".$theme)){
				$theme  =   C('SP_DEFAULT_THEME');
			}
			cookie('think_template',$theme,864000);
		}
		
		$theme_suffix="";
		
		if(C('MOBILE_TPL_ENABLED') && sp_is_mobile()){//开启手机模板支持
		    
		    if (C('LANG_SWITCH_ON',null,false)){
		        if(file_exists($tmpl_path."/".$theme."_mobile_".LANG_SET)){//优先级最高
		            $theme_suffix  =  "_mobile_".LANG_SET;
		        }elseif (file_exists($tmpl_path."/".$theme."_mobile")){
		            $theme_suffix  =  "_mobile";
		        }elseif (file_exists($tmpl_path."/".$theme."_".LANG_SET)){
		            $theme_suffix  =  "_".LANG_SET;
		        }
		    }else{
    		    if(file_exists($tmpl_path."/".$theme."_mobile")){
    		        $theme_suffix  =  "_mobile";
    		    }
		    }
		}else{
		    $lang_suffix="_".LANG_SET;
		    if (C('LANG_SWITCH_ON',null,false) && file_exists($tmpl_path."/".$theme.$lang_suffix)){
		        $theme_suffix = $lang_suffix;
		    }
		}
		
		$theme=$theme.$theme_suffix;
		
		C('SP_DEFAULT_THEME',$theme);
		
		$current_tmpl_path=$tmpl_path.$theme."/";
		// 获取当前主题的模版路径
		define('THEME_PATH', $current_tmpl_path);
		
		C("TMPL_PARSE_STRING.__TMPL__",__ROOT__."/".$current_tmpl_path);
		
		C('SP_VIEW_PATH',$tmpl_path);
		C('DEFAULT_THEME',$theme);
		
		define("SP_CURRENT_THEME", $theme);
		
		if(is_file($template)) {
			return $template;
		}
		$depr       =   C('TMPL_FILE_DEPR');
		$template   =   str_replace(':', $depr, $template);
		
		// 获取当前模块
		$module   =  'Comment';
		if(strpos($template,'@')){ // 跨模块调用模版文件
			list($module,$template)  =   explode('@',$template);
		}
		
		
		// 分析模板文件规则
		if('' == $template) {
			// 如果模板文件名为空 按照默认规则定位
			$template = "/".CONTROLLER_NAME . $depr . ACTION_NAME;
		}elseif(false === strpos($template, '/')){
			$template = "/".CONTROLLER_NAME . $depr . $template;
		}
		
		$file = sp_add_template_file_suffix($current_tmpl_path.$module.$template);
		$file= str_replace("//",'/',$file);
		if(!file_exists_case($file)) E(L('_TEMPLATE_NOT_EXIST_').':'.$file);

		return $file;
	}
	
	// /**
	//  * 自动定位模板文件
	//  * @access protected
	//  * @param string $template 模板文件规则
	//  * @return string
	//  */
	// public function parseTemplate($template='') {
	// 	// 获取当前主题名称
	// 	$theme      =    C('SP_DEFAULT_THEME');
	// 	if(C('TMPL_DETECT_THEME')) {// 自动侦测模板主题
	// 		$t = C('VAR_TEMPLATE');
	// 		if (isset($_GET[$t])){
	// 			$theme = $_GET[$t];
	// 		}elseif(cookie('think_template')){
	// 			$theme = cookie('think_template');
	// 		}
	// 		if(!file_exists($tmpl_path."/".$theme)){
	// 			$theme  =   C('SP_DEFAULT_THEME');
	// 		}
	// 		cookie('think_template',$theme,864000);
	// 	}
	
	
	// 	$depr       =   C('TMPL_FILE_DEPR');
	// 	$template   =   str_replace(':', $depr, $template);
	
	// 	// 获取当前模版分组
	// 	$group      =   "Comment";
	// 	// 获取当前主题的模版路径
	// 	if(1==C('APP_GROUP_MODE')){ // 独立分组模式
	// 		define('THEME_PATH',   $tmpl_path.$theme."/");
	// 		define('APP_TMPL_PATH',__ROOT__.'/'.basename($tmpl_path).'/'.$theme."/");
	// 	}
	// 	// 分析模板文件规则
	// 	if('' == $template) {
	// 		// 如果模板文件名为空 按照默认规则定位
	// 		$template = MODULE_NAME . $depr . ACTION_NAME;
	// 	}elseif(false === strpos($template, '/')){
	// 		$template = MODULE_NAME . $depr . $template;
	// 	}
	// 	$templateFile = sp_add_template_file_suffix(THEME_PATH.$group.$template);
	// 	if(!file_exists_case($templateFile))
	// 		throw_exception(L('_TEMPLATE_NOT_EXIST_').'['.$templateFile.']');
	// 	return $templateFile;
	// }


打赏

评论

暂时关闭,稍后恢复~
文档请看10遍以上!有问题可加QQ群!
发表话题

源素材推荐

提问必知

0.话题发布后没及时显示,请联系官方QQ群管理;
1.话题支持代码,qq截屏直接粘贴,和QQ群一样;
2.问题描述清,比如服务器版本,程序版本;
3.能上代码,就不用文字;
4.把问题发到话题后再发QQ群;
5.如果感觉回复者解答的不错,可以发红包!
6.多帮助别人也是对自己的锻炼!
7.付费讨论中只有提问者和付费用户才可以查看回复

积分规则

1.评论积分+1;每天最多10次奖励
2.发布话题积分+1;每天最多5次奖励
3.垃圾评论积分-500;
4.黄色,暴力,违反我国法律评论直接封号


ThinkCMF 8.0.1发布啦!节日快乐! 立即体验!