Template类增加layout方法 模板引擎驱动支持直接调用模板引擎的方法

This commit is contained in:
thinkphp
2016-02-20 18:24:55 +08:00
parent 5217692224
commit b7632a5a52
2 changed files with 56 additions and 40 deletions

View File

@@ -212,6 +212,25 @@ class Template
$this->storage->read($cacheFile, $this->data); $this->storage->read($cacheFile, $this->data);
} }
/**
* 设置布局
* @access public
* @param mixed $name 布局模板名称 false 则关闭布局
* @return void
*/
public function layout($name)
{
if (false !== $name) {
$this->config['layout_on'] = true;
if (is_string($name)) {
$this->config['layout_name'] = $name;
}
} else {
// 关闭布局
$this->config['layout_on'] = false;
}
}
/** /**
* 检查编译缓存是否有效 * 检查编译缓存是否有效
* 如果无效则需要重新编译 * 如果无效则需要重新编译

View File

@@ -8,7 +8,6 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com> // | Author: liu21st <liu21st@gmail.com>
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace think\view\driver; namespace think\view\driver;
use think\Template; use think\Template;
@@ -16,33 +15,31 @@ use think\Template;
class Think class Think
{ {
private $template = null; private $template = null;
public function __construct($config = []) public function __construct($config = [])
{ {
$this->template = new Template($config); $this->template = new Template($config);
} }
public function fetch($template, $data = [], $cache = []) /**
* 渲染模板文件
* @access public
* @param string $template 模板文件或者内容
* @param array $data 模板变量
* @param array $config 模板参数
* @return void
*/
public function fetch($template, $data = [], $config = [])
{ {
if (is_file($template)) { if (is_file($template)) {
$this->template->display($template, $data, $cache); $this->template->display($template, $data, $config);
} else { } else {
$this->template->fetch($template, $data); $this->template->fetch($template, $data);
} }
} }
/** public function __call($method, $params)
* 修改模板引擎配置项
* @access public
* @param array|string $config
* @return string|array
*/
public function config($config)
{ {
if(is_array($config)){ return call_user_func_array([$this->template, $method], $params);
$this->template->config($config);
return $this;
}else{
return $this->template->config($config);
}
} }
} }