mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 23:22:48 +08:00
规范Response中result/success/error方法使用,与view使用方法保持一致,同时完美兼容单元测试
使用方法:
if(false){
return Response::error('error msg');
}else{
return Response::success('success msg');
}
This commit is contained in:
@@ -111,7 +111,7 @@ class App
|
|||||||
// 操作方法执行完成监听
|
// 操作方法执行完成监听
|
||||||
APP_HOOK && Hook::listen('action_end', $data);
|
APP_HOOK && Hook::listen('action_end', $data);
|
||||||
// 输出数据
|
// 输出数据
|
||||||
return Response::send($data, '', Config::get('response_return'));
|
return Response::send($data, Config::get('default_return_type'), Config::get('response_return'));
|
||||||
} else {
|
} else {
|
||||||
// 操作方法不是Public 抛出异常
|
// 操作方法不是Public 抛出异常
|
||||||
throw new \ReflectionException();
|
throw new \ReflectionException();
|
||||||
|
|||||||
@@ -137,11 +137,7 @@ class Response
|
|||||||
'time' => NOW_TIME,
|
'time' => NOW_TIME,
|
||||||
'data' => $data,
|
'data' => $data,
|
||||||
];
|
];
|
||||||
|
return $result;
|
||||||
self::$data = $result;
|
|
||||||
if ($type) {
|
|
||||||
self::$type = $type;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -159,20 +155,16 @@ class Response
|
|||||||
'code' => 1,
|
'code' => 1,
|
||||||
'msg' => $msg,
|
'msg' => $msg,
|
||||||
'data' => $data,
|
'data' => $data,
|
||||||
'url' => $url ? $url : $_SERVER["HTTP_REFERER"],
|
'url' => $url ?: $_SERVER["HTTP_REFERER"],
|
||||||
'wait' => $wait,
|
'wait' => $wait,
|
||||||
];
|
];
|
||||||
$type = IS_AJAX ? Config::get('default_ajax_return') : Config::get('default_return_type');
|
if(IS_AJAX){
|
||||||
if ('html' == $type) {
|
Config::set('default_return_type', Config::get('default_ajax_return'));
|
||||||
$view = new \think\View();
|
|
||||||
$result = $view->fetch(Config::get('dispatch_jump_tmpl'), $result);
|
|
||||||
}
|
}
|
||||||
self::$data = $result;
|
if ('html' == Config::get('default_return_type')) {
|
||||||
if ($type) {
|
$result = \think\View::getInstance()->fetch(Config::get('dispatch_jump_tmpl'), $result);
|
||||||
self::$type = $type;
|
|
||||||
}
|
}
|
||||||
self::$isExit = true;
|
return $result;
|
||||||
self::send();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -190,20 +182,16 @@ class Response
|
|||||||
'code' => 0,
|
'code' => 0,
|
||||||
'msg' => $msg,
|
'msg' => $msg,
|
||||||
'data' => $data,
|
'data' => $data,
|
||||||
'url' => $url ? $url : 'javascript:history.back(-1);',
|
'url' => $url ?: 'javascript:history.back(-1);',
|
||||||
'wait' => $wait,
|
'wait' => $wait,
|
||||||
];
|
];
|
||||||
$type = IS_AJAX ? Config::get('default_ajax_return') : Config::get('default_return_type');
|
if(IS_AJAX){
|
||||||
if ('html' == $type) {
|
Config::set('default_return_type', Config::get('default_ajax_return'));
|
||||||
$view = new \think\View();
|
|
||||||
$result = $view->fetch(Config::get('dispatch_jump_tmpl'), $result);
|
|
||||||
}
|
}
|
||||||
self::$data = $result;
|
if ('html' == Config::get('default_return_type')) {
|
||||||
if ($type) {
|
$result = \think\View::getInstance()->fetch(Config::get('dispatch_jump_tmpl'), $result);
|
||||||
self::$type = $type;
|
|
||||||
}
|
}
|
||||||
self::$isExit = true;
|
return $result;
|
||||||
self::send();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user