mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 20:52: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);
|
||||
// 输出数据
|
||||
return Response::send($data, '', Config::get('response_return'));
|
||||
return Response::send($data, Config::get('default_return_type'), Config::get('response_return'));
|
||||
} else {
|
||||
// 操作方法不是Public 抛出异常
|
||||
throw new \ReflectionException();
|
||||
|
||||
@@ -137,11 +137,7 @@ class Response
|
||||
'time' => NOW_TIME,
|
||||
'data' => $data,
|
||||
];
|
||||
|
||||
self::$data = $result;
|
||||
if ($type) {
|
||||
self::$type = $type;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,20 +155,16 @@ class Response
|
||||
'code' => 1,
|
||||
'msg' => $msg,
|
||||
'data' => $data,
|
||||
'url' => $url ? $url : $_SERVER["HTTP_REFERER"],
|
||||
'url' => $url ?: $_SERVER["HTTP_REFERER"],
|
||||
'wait' => $wait,
|
||||
];
|
||||
$type = IS_AJAX ? Config::get('default_ajax_return') : Config::get('default_return_type');
|
||||
if ('html' == $type) {
|
||||
$view = new \think\View();
|
||||
$result = $view->fetch(Config::get('dispatch_jump_tmpl'), $result);
|
||||
if(IS_AJAX){
|
||||
Config::set('default_return_type', Config::get('default_ajax_return'));
|
||||
}
|
||||
self::$data = $result;
|
||||
if ($type) {
|
||||
self::$type = $type;
|
||||
if ('html' == Config::get('default_return_type')) {
|
||||
$result = \think\View::getInstance()->fetch(Config::get('dispatch_jump_tmpl'), $result);
|
||||
}
|
||||
self::$isExit = true;
|
||||
self::send();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -190,20 +182,16 @@ class Response
|
||||
'code' => 0,
|
||||
'msg' => $msg,
|
||||
'data' => $data,
|
||||
'url' => $url ? $url : 'javascript:history.back(-1);',
|
||||
'url' => $url ?: 'javascript:history.back(-1);',
|
||||
'wait' => $wait,
|
||||
];
|
||||
$type = IS_AJAX ? Config::get('default_ajax_return') : Config::get('default_return_type');
|
||||
if ('html' == $type) {
|
||||
$view = new \think\View();
|
||||
$result = $view->fetch(Config::get('dispatch_jump_tmpl'), $result);
|
||||
if(IS_AJAX){
|
||||
Config::set('default_return_type', Config::get('default_ajax_return'));
|
||||
}
|
||||
self::$data = $result;
|
||||
if ($type) {
|
||||
self::$type = $type;
|
||||
if ('html' == Config::get('default_return_type')) {
|
||||
$result = \think\View::getInstance()->fetch(Config::get('dispatch_jump_tmpl'), $result);
|
||||
}
|
||||
self::$isExit = true;
|
||||
self::send();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user