mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
改进模板引擎
This commit is contained in:
@@ -1527,6 +1527,7 @@ class Route
|
||||
* 解析URL地址为 模块/控制器/操作
|
||||
* @access private
|
||||
* @param string $url URL地址
|
||||
* @param bool $convert 是否自动转换URL地址
|
||||
* @return array
|
||||
*/
|
||||
private static function parseModule($url, $convert = false)
|
||||
|
||||
@@ -15,6 +15,8 @@ use think\Exception;
|
||||
|
||||
class File
|
||||
{
|
||||
protected $cacheFile;
|
||||
|
||||
/**
|
||||
* 写入编译缓存
|
||||
* @param string $cacheFile 缓存的文件名
|
||||
@@ -42,20 +44,13 @@ class File
|
||||
*/
|
||||
public function read($cacheFile, $vars = [])
|
||||
{
|
||||
$this->cacheFile = $cacheFile;
|
||||
if (!empty($vars) && is_array($vars)) {
|
||||
// 模板阵列变量分解成为独立变量
|
||||
if (isset($vars['cacheFile'])) {
|
||||
$_think_cacheFile = $cacheFile;
|
||||
$cacheFile = $vars['cacheFile'];
|
||||
unset($vars['cacheFile'], $vars['_think_cacheFile']);
|
||||
extract($vars, EXTR_OVERWRITE);
|
||||
include $_think_cacheFile;
|
||||
return;
|
||||
}
|
||||
extract($vars);
|
||||
extract($vars, EXTR_OVERWRITE);
|
||||
}
|
||||
//载入模版缓存文件
|
||||
include $cacheFile;
|
||||
include $this->cacheFile;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -32,6 +32,8 @@ class Php
|
||||
// 默认模板渲染规则 1 解析为小写+下划线 2 全部转换小写
|
||||
'auto_rule' => 1,
|
||||
];
|
||||
protected $template;
|
||||
protected $content;
|
||||
|
||||
public function __construct($config = [])
|
||||
{
|
||||
@@ -70,18 +72,12 @@ class Php
|
||||
if (!is_file($template)) {
|
||||
throw new TemplateNotFoundException('template not exists:' . $template, $template);
|
||||
}
|
||||
$this->template = $template;
|
||||
// 记录视图信息
|
||||
App::$debug && Log::record('[ VIEW ] ' . $template . ' [ ' . var_export(array_keys($data), true) . ' ]', 'info');
|
||||
if (isset($data['template'])) {
|
||||
$__template__ = $template;
|
||||
$template = $data['template'];
|
||||
unset($data['template'], $data['__template__']);
|
||||
extract($data, EXTR_OVERWRITE);
|
||||
include $__template__;
|
||||
} else {
|
||||
extract($data, EXTR_OVERWRITE);
|
||||
include $template;
|
||||
}
|
||||
|
||||
extract($data, EXTR_OVERWRITE);
|
||||
include $template;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,16 +89,10 @@ class Php
|
||||
*/
|
||||
public function display($content, $data = [])
|
||||
{
|
||||
if (isset($data['content'])) {
|
||||
$__content__ = $content;
|
||||
$content = $data['content'];
|
||||
unset($data['content'], $data['__content__']);
|
||||
extract($data, EXTR_OVERWRITE);
|
||||
eval('?>' . $__content__);
|
||||
} else {
|
||||
extract($data, EXTR_OVERWRITE);
|
||||
eval('?>' . $content);
|
||||
}
|
||||
$this->content = $content;
|
||||
|
||||
extract($data, EXTR_OVERWRITE);
|
||||
eval('?>' . $this->content);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user