mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-06 07:02:47 +08:00
View类增加__set __get __isset 方法用于操作模板变量
This commit is contained in:
@@ -87,11 +87,11 @@ class View
|
|||||||
*/
|
*/
|
||||||
public function engine($engine, array $config = [])
|
public function engine($engine, array $config = [])
|
||||||
{
|
{
|
||||||
if('php'==$engine){
|
if ('php' == $engine) {
|
||||||
$this->engine = 'php';
|
$this->engine = 'php';
|
||||||
}else{
|
} else {
|
||||||
$class = '\\think\\view\\driver\\' . ucwords($engine);
|
$class = '\\think\\view\\driver\\' . ucwords($engine);
|
||||||
$this->engine = new $class($config);
|
$this->engine = new $class($config);
|
||||||
}
|
}
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@@ -125,8 +125,8 @@ class View
|
|||||||
*
|
*
|
||||||
* @param string $template 模板文件名或者内容
|
* @param string $template 模板文件名或者内容
|
||||||
* @param array $vars 模板输出变量
|
* @param array $vars 模板输出变量
|
||||||
* @param array $cache 模板缓存参数
|
* @param array $cache 模板缓存参数
|
||||||
* @param bool $renderContent
|
* @param bool $renderContent 是否渲染内容
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
@@ -216,6 +216,7 @@ class View
|
|||||||
/**
|
/**
|
||||||
* 获取当前的模板主题
|
* 获取当前的模板主题
|
||||||
* @access private
|
* @access private
|
||||||
|
* @param string $module 模块名
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function getTemplateTheme($module)
|
private function getTemplateTheme($module)
|
||||||
@@ -263,4 +264,36 @@ class View
|
|||||||
return $tmplPath . $theme;
|
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]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user