mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-09 08:02:48 +08:00
Template类增加layout方法 模板引擎驱动支持直接调用模板引擎的方法
This commit is contained in:
@@ -212,6 +212,25 @@ class Template
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查编译缓存是否有效
|
||||
* 如果无效则需要重新编译
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace think\view\driver;
|
||||
|
||||
use think\Template;
|
||||
@@ -16,33 +15,31 @@ use think\Template;
|
||||
class Think
|
||||
{
|
||||
private $template = null;
|
||||
|
||||
public function __construct($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)) {
|
||||
$this->template->display($template, $data, $cache);
|
||||
$this->template->display($template, $data, $config);
|
||||
} else {
|
||||
$this->template->fetch($template, $data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改模板引擎配置项
|
||||
* @access public
|
||||
* @param array|string $config
|
||||
* @return string|array
|
||||
*/
|
||||
public function config($config)
|
||||
public function __call($method, $params)
|
||||
{
|
||||
if(is_array($config)){
|
||||
$this->template->config($config);
|
||||
return $this;
|
||||
}else{
|
||||
return $this->template->config($config);
|
||||
}
|
||||
return call_user_func_array([$this->template, $method], $params);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user