mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 15:12:48 +08:00
View类增加share静态方法 用于静态赋值模板变量
This commit is contained in:
@@ -19,6 +19,8 @@ class View
|
|||||||
public $engine;
|
public $engine;
|
||||||
// 模板变量
|
// 模板变量
|
||||||
protected $data = [];
|
protected $data = [];
|
||||||
|
// 用于静态赋值的模板变量
|
||||||
|
protected static $var = [];
|
||||||
// 视图输出替换
|
// 视图输出替换
|
||||||
protected $replace = [];
|
protected $replace = [];
|
||||||
|
|
||||||
@@ -50,6 +52,22 @@ class View
|
|||||||
return self::$instance;
|
return self::$instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模板变量静态赋值
|
||||||
|
* @access public
|
||||||
|
* @param mixed $name 变量名
|
||||||
|
* @param mixed $value 变量值
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function share($name, $value = '')
|
||||||
|
{
|
||||||
|
if (is_array($name)) {
|
||||||
|
self::$var = array_merge(self::$var, $name);
|
||||||
|
} else {
|
||||||
|
self::$var[$name] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 模板变量赋值
|
* 模板变量赋值
|
||||||
* @access public
|
* @access public
|
||||||
@@ -116,7 +134,7 @@ class View
|
|||||||
public function fetch($template = '', $vars = [], $replace = [], $config = [], $renderContent = false)
|
public function fetch($template = '', $vars = [], $replace = [], $config = [], $renderContent = false)
|
||||||
{
|
{
|
||||||
// 模板变量
|
// 模板变量
|
||||||
$vars = array_merge($this->data, $vars);
|
$vars = array_merge(self::$var, $this->data, $vars);
|
||||||
|
|
||||||
// 页面缓存
|
// 页面缓存
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|||||||
Reference in New Issue
Block a user