From c070940b95b727dcb49b39b746bb1cd5ba71aa13 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 20 Dec 2015 10:53:33 +0800 Subject: [PATCH] =?UTF-8?q?View=E7=B1=BB=E5=A2=9E=E5=8A=A0=5F=5Fset=20=5F?= =?UTF-8?q?=5Fget=20=5F=5Fisset=20=E6=96=B9=E6=B3=95=E7=94=A8=E4=BA=8E?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E6=A8=A1=E6=9D=BF=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/view.php | 47 +++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/library/think/view.php b/library/think/view.php index c8d41e06..d831c8ee 100644 --- a/library/think/view.php +++ b/library/think/view.php @@ -87,11 +87,11 @@ class View */ public function engine($engine, array $config = []) { - if('php'==$engine){ - $this->engine = 'php'; - }else{ - $class = '\\think\\view\\driver\\' . ucwords($engine); - $this->engine = new $class($config); + if ('php' == $engine) { + $this->engine = 'php'; + } else { + $class = '\\think\\view\\driver\\' . ucwords($engine); + $this->engine = new $class($config); } return $this; } @@ -125,8 +125,8 @@ class View * * @param string $template 模板文件名或者内容 * @param array $vars 模板输出变量 - * @param array $cache 模板缓存参数 - * @param bool $renderContent + * @param array $cache 模板缓存参数 + * @param bool $renderContent 是否渲染内容 * * @return string * @throws Exception @@ -216,6 +216,7 @@ class View /** * 获取当前的模板主题 * @access private + * @param string $module 模块名 * @return string */ private function getTemplateTheme($module) @@ -263,4 +264,36 @@ class View return $tmplPath . $theme; } + /** + * 模板变量赋值 + * @access public + * @param string $name 变量名 + * @param mixed $value 变量值 + */ + public function __set($name, $value) + { + $this->data[$name] = $value; + } + + /** + * 取得模板显示变量的值 + * @access protected + * @param string $name 模板变量 + * @return mixed + */ + public function __get($name) + { + return $this->data[$name]; + } + + /** + * 检测模板变量是否设置 + * @access public + * @param string $name 模板变量名 + * @return bool + */ + public function __isset($name) + { + return isset($this->data[$name]); + } }