mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 15:12:48 +08:00
视图驱动类增加exists方法用于判断模板文件是否存在
This commit is contained in:
@@ -31,6 +31,21 @@ class Php
|
|||||||
$this->config = array_merge($this->config, $config);
|
$this->config = array_merge($this->config, $config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测是否存在模板文件
|
||||||
|
* @access public
|
||||||
|
* @param string $template 模板文件或者模板规则
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function exists($template)
|
||||||
|
{
|
||||||
|
if (!is_file($template)) {
|
||||||
|
// 获取模板文件名
|
||||||
|
$template = $this->parseTemplate($template);
|
||||||
|
}
|
||||||
|
return is_file($template);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 渲染模板文件
|
* 渲染模板文件
|
||||||
* @access public
|
* @access public
|
||||||
@@ -40,12 +55,8 @@ class Php
|
|||||||
*/
|
*/
|
||||||
public function fetch($template, $data = [])
|
public function fetch($template, $data = [])
|
||||||
{
|
{
|
||||||
if (!is_file($template)) {
|
|
||||||
// 获取模板文件名
|
|
||||||
$template = $this->parseTemplate($template);
|
|
||||||
}
|
|
||||||
// 模板不存在 抛出异常
|
// 模板不存在 抛出异常
|
||||||
if (!is_file($template)) {
|
if (!$this->exists($template)) {
|
||||||
throw new Exception('template file not exists:' . $template, 10700);
|
throw new Exception('template file not exists:' . $template, 10700);
|
||||||
}
|
}
|
||||||
// 记录视图信息
|
// 记录视图信息
|
||||||
|
|||||||
@@ -40,6 +40,21 @@ class Think
|
|||||||
$this->template = new Template($this->config);
|
$this->template = new Template($this->config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测是否存在模板文件
|
||||||
|
* @access public
|
||||||
|
* @param string $template 模板文件或者模板规则
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function exists($template)
|
||||||
|
{
|
||||||
|
if (!is_file($template)) {
|
||||||
|
// 获取模板文件名
|
||||||
|
$template = $this->parseTemplate($template);
|
||||||
|
}
|
||||||
|
return is_file($template);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 渲染模板文件
|
* 渲染模板文件
|
||||||
* @access public
|
* @access public
|
||||||
@@ -50,12 +65,8 @@ class Think
|
|||||||
*/
|
*/
|
||||||
public function fetch($template, $data = [], $config = [])
|
public function fetch($template, $data = [], $config = [])
|
||||||
{
|
{
|
||||||
if (!is_file($template)) {
|
|
||||||
// 获取模板文件名
|
|
||||||
$template = $this->parseTemplate($template);
|
|
||||||
}
|
|
||||||
// 模板不存在 抛出异常
|
// 模板不存在 抛出异常
|
||||||
if (!is_file($template)) {
|
if (!$this->exists($template)) {
|
||||||
throw new Exception('template file not exists:' . $template, 10700);
|
throw new Exception('template file not exists:' . $template, 10700);
|
||||||
}
|
}
|
||||||
// 记录视图信息
|
// 记录视图信息
|
||||||
|
|||||||
Reference in New Issue
Block a user