ThinkPHP2.1 增加PHPCMS模板引擎,支持PC標簽(get,json)
本人經常使用PHPCMS模板引擎。
用ThinkPHP2.1 自帶的,感覺不爽,花點時間增加了個PHPCMS模板引擎
BY 夜色紫宸風
功能:PHPCMS模板解析引擎,支持PC標簽(get,json),也可以使用ThinkPHP2.1的模板數據,都支持
TemplatePhpcms.class.php
把這個文件放到 ThinkPHP\Lib\Think\Util\Template 文件夾中
<?php /** +------------------------------------------------------------------------------ * TemplateLite模板引擎解析類 +------------------------------------------------------------------------------ * @category Think * @package Think * @subpackage Util * @author liu21st <liu21st@gmail.com> * @version $Id$ +------------------------------------------------------------------------------ */ class TemplatePhpcms { /** +---------------------------------------------------------- * 渲染模板輸出 +---------------------------------------------------------- * @access public +---------------------------------------------------------- * @param string $templateFile 模板文件名 * @param array $var 模板變量 * @param string $charset 模板輸出字符集 +---------------------------------------------------------- * @return void +---------------------------------------------------------- */ public function fetch($templateFile, $var, $charset) { $templateFile = substr ( $templateFile, strlen ( TMPL_PATH ) ); $t=explode('/',$templateFile); @extract($var); include template($t[1],$t[2],$t[0]); } } /** * 模板調用 * * @param $module * @param $template * @param $istag * @return unknown_type */ function template($module = 'Index', $template = 'index', $style = 'default') { $templateFile = $style.'/'.$module.'/'.$template; vendor ( "TemplatePhpcms.class#phpcms" ); if (C ( 'TMPL_ENGINE_CONFIG' )) { $config = C ( 'TMPL_ENGINE_CONFIG' ); } else { $config = array ('template_dir' => TMPL_PATH, 'cache_dir' => CACHE_PATH, 'compile_dir' => TEMP_PATH ); } $tpl = new Template_Phpcms ( $config ); $tpl->template_compile ( $templateFile ); return $config['cache_dir'].basename($template).'.php'; } ?>
class.phpcms.php
把這個文件放到 ThinkPHP\Vendor\TemplatePhpcms 文件夾中(TemplatePhpcms 這個目錄要新建)
我倒。我汗。。貼上來,源碼亂了。。。。
暈。壓縮文件吧。。。
https://download.csdn.net/detail/wljk506/3798209
最後更新:2017-04-02 06:52:06