mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 23:22:48 +08:00
改写View类的instance方法
This commit is contained in:
@@ -177,12 +177,14 @@ class Response
|
|||||||
'url' => $url ?: $_SERVER["HTTP_REFERER"],
|
'url' => $url ?: $_SERVER["HTTP_REFERER"],
|
||||||
'wait' => $wait,
|
'wait' => $wait,
|
||||||
];
|
];
|
||||||
$type = Config::get('default_return_type');
|
|
||||||
if (IS_AJAX) {
|
if (IS_AJAX) {
|
||||||
$type = Config::get('default_ajax_return');
|
$type = Config::get('default_ajax_return');
|
||||||
|
} else {
|
||||||
|
$type = Config::get('default_return_type');
|
||||||
}
|
}
|
||||||
if ('html' == $type) {
|
if ('html' == $type) {
|
||||||
$result = \think\View::getInstance()->fetch(Config::get('dispatch_jump_tmpl'), $result);
|
$result = \think\View::instance()->fetch(Config::get('dispatch_jump_tmpl'), $result);
|
||||||
}
|
}
|
||||||
self::type($type);
|
self::type($type);
|
||||||
return $result;
|
return $result;
|
||||||
@@ -211,12 +213,14 @@ class Response
|
|||||||
'url' => $url ?: 'javascript:history.back(-1);',
|
'url' => $url ?: 'javascript:history.back(-1);',
|
||||||
'wait' => $wait,
|
'wait' => $wait,
|
||||||
];
|
];
|
||||||
$type = Config::get('default_return_type');
|
|
||||||
if (IS_AJAX) {
|
if (IS_AJAX) {
|
||||||
$type = Config::get('default_ajax_return');
|
$type = Config::get('default_ajax_return');
|
||||||
|
} else {
|
||||||
|
$type = Config::get('default_return_type');
|
||||||
}
|
}
|
||||||
if ('html' == $type) {
|
if ('html' == $type) {
|
||||||
$result = \think\View::getInstance()->fetch(Config::get('dispatch_jump_tmpl'), $result);
|
$result = \think\View::instance()->fetch(Config::get('dispatch_jump_tmpl'), $result);
|
||||||
}
|
}
|
||||||
self::type($type);
|
self::type($type);
|
||||||
return $result;
|
return $result;
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ namespace think;
|
|||||||
|
|
||||||
class View
|
class View
|
||||||
{
|
{
|
||||||
|
// 视图实例
|
||||||
|
protected static $instance = null;
|
||||||
// 模板引擎实例
|
// 模板引擎实例
|
||||||
protected $engine = null;
|
protected $engine = null;
|
||||||
// 模板主题名称
|
// 模板主题名称
|
||||||
@@ -40,13 +42,18 @@ class View
|
|||||||
$this->config($config);
|
$this->config($config);
|
||||||
$this->engine($this->config['engine_type']);
|
$this->engine($this->config['engine_type']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化视图
|
* 初始化视图
|
||||||
* @access public
|
* @access public
|
||||||
* @param array $config 配置参数
|
* @param array $config 配置参数
|
||||||
*/
|
*/
|
||||||
static public function getInstance(array $config = []){
|
public static function instance(array $config = [])
|
||||||
return new self($config);
|
{
|
||||||
|
if (is_null(self::$instance)) {
|
||||||
|
self::$instance = new self($config);
|
||||||
|
}
|
||||||
|
return self::$instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ trait View
|
|||||||
{
|
{
|
||||||
// 模板引擎参数
|
// 模板引擎参数
|
||||||
if (is_null($this->view)) {
|
if (is_null($this->view)) {
|
||||||
$this->view = new \think\View(Config::get()); // 只能这样写,不然view会冲突
|
$this->view = \think\View::instance(Config::get()); // 只能这样写,不然view会冲突
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,6 +46,10 @@ if (APP_HOOK && isset($mode['tags'])) {
|
|||||||
if (APP_AUTO_BUILD && is_file(APP_PATH . 'build.php')) {
|
if (APP_AUTO_BUILD && is_file(APP_PATH . 'build.php')) {
|
||||||
Build::run(include APP_PATH . 'build.php');
|
Build::run(include APP_PATH . 'build.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (IN_UNIT_TEST) {
|
||||||
Loader::addNamespace('tests', TEST_PATH);
|
Loader::addNamespace('tests', TEST_PATH);
|
||||||
|
} else {
|
||||||
// 执行应用
|
// 执行应用
|
||||||
!IN_UNIT_TEST && App::run();
|
App::run();
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user