From 9d0f671d2aa119eca3e5bae1d54db3127ed08ade Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 29 Mar 2013 11:52:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E5=BC=95=E6=93=8E=E7=B1=BB?= =?UTF-8?q?=E7=9A=84display=E5=92=8Cfetch=E6=96=B9=E6=B3=95=E6=94=B9?= =?UTF-8?q?=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Think/Template.php | 22 ++++++++++------------ Think/View/Driver/Think.php | 12 ++++-------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/Think/Template.php b/Think/Template.php index a40b3ca4..44cafb1d 100644 --- a/Think/Template.php +++ b/Think/Template.php @@ -103,18 +103,18 @@ class Template { public function get($name){ return $this->tVar[$name]; } + /** * 渲染模板文件 * @access public * @param string $template 模板文件 - * @param array $var 模板变量 - * @param string $prefix 模板标识前缀 + * @param array $vars 模板变量 + * @param string $cacheId 模板缓存标识 * @return void */ - public function display($template,$prefix='',$cacheId='') { - $prefix = $prefix ? $prefix : $this->config['cache_prefix']; + public function display($template,$vars=[],$cacheId='') { $template = $this->parseTemplateFile($template); - $cacheFile = $this->config['cache_path'].$prefix.md5($template).$this->config['cache_suffix']; + $cacheFile = $this->config['cache_path'].$this->config['cache_prefix'].md5($template).$this->config['cache_suffix']; if(!$this->checkCache($template,$cacheFile)) { // 缓存无效 // 模板编译 $this->compiler(file_get_contents($template),$cacheFile); @@ -123,7 +123,7 @@ class Template { ob_start(); ob_implicit_flush(0); // 读取编译存储 - $this->storage->read($cacheFile,$this->tVar); + $this->storage->read($cacheFile,$vars?$vars:$this->tVar); // 获取并清空缓存 $content = ob_get_clean(); if($cacheId && $this->config['display_cache']) { @@ -137,19 +137,17 @@ class Template { * 渲染模板内容 * @access public * @param string $content 模板内容 - * @param array $var 模板变量 - * @param string $prefix 模板标识前缀 + * @param array $vars 模板变量 * @return void */ - public function fetch($content,$prefix='') { - $prefix = $prefix ? $prefix : $this->config['cache_prefix']; - $cacheFile = $this->config['cache_path'].$prefix.md5($content).$this->config['cache_suffix']; + public function fetch($content,$vars=[]) { + $cacheFile = $this->config['cache_path'].$this->config['cache_prefix'].md5($content).$this->config['cache_suffix']; if(!$this->checkCache($content,$cacheFile)) { // 缓存无效 // 模板编译 $this->compiler($content,$cacheFile); } // 读取编译存储 - $this->storage->read($cacheFile,$this->tVar); + $this->storage->read($cacheFile,$vars?$vars:$this->tVar); } /** diff --git a/Think/View/Driver/Think.php b/Think/View/Driver/Think.php index 392fc116..c442cc7d 100644 --- a/Think/View/Driver/Think.php +++ b/Think/View/Driver/Think.php @@ -13,16 +13,12 @@ namespace Think\View\Driver; use Think\Template; class Think { private $template = null; - public function __construct($config=array()){ - $tpl = new Template($config); - $this->template = $tpl; - //$tpl->tpl_path = MODULE_PATH.'view/'; - //$tpl->cache_path = MODULE_PATH.'cache/'; + public function __construct($config=[]){ + $this->template = new Template($config); } - public function fetch($template,$data=array()){ - $this->template->assign($data); - $this->template->display($template); + public function fetch($template,$data=[]){ + $this->template->display($template,$data); } } \ No newline at end of file