mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-08 07:32:48 +08:00
增加默认模板替换字符串 __ROOT__ __STATIC__ __JS__ __CSS__ __URL__ 都不带域名
This commit is contained in:
@@ -11,6 +11,9 @@
|
|||||||
|
|
||||||
namespace think;
|
namespace think;
|
||||||
|
|
||||||
|
use think\Loader;
|
||||||
|
use think\Request;
|
||||||
|
|
||||||
class View
|
class View
|
||||||
{
|
{
|
||||||
// 视图实例
|
// 视图实例
|
||||||
@@ -30,11 +33,25 @@ class View
|
|||||||
* @param array $engine 模板引擎参数
|
* @param array $engine 模板引擎参数
|
||||||
* @param array $replace 字符串替换参数
|
* @param array $replace 字符串替换参数
|
||||||
*/
|
*/
|
||||||
public function __construct($engine = [], $replace = [])
|
public function __construct($engine = [], array $replace = [])
|
||||||
{
|
{
|
||||||
// 初始化模板引擎
|
// 初始化模板引擎
|
||||||
$this->engine((array) $engine);
|
$this->engine((array) $engine);
|
||||||
$this->replace = $replace;
|
// 基础替换字符串
|
||||||
|
$request = Request::instance();
|
||||||
|
$base = $request->root();
|
||||||
|
$root = strpos($base, '.') ? dirname($base) : $base;
|
||||||
|
if ('' != $root) {
|
||||||
|
$root = '/' . $root;
|
||||||
|
}
|
||||||
|
$baseReplace = [
|
||||||
|
'__ROOT__' => $root,
|
||||||
|
'__URL__' => $base . '/' . $request->module() . '/' . Loader::parseName($request->controller()),
|
||||||
|
'__STATIC__' => $root . '/static',
|
||||||
|
'__CSS__' => $root . '/static/css',
|
||||||
|
'__JS__' => $root . '/static/js',
|
||||||
|
];
|
||||||
|
$this->replace = array_merge($baseReplace, $replace);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user