Skip to content

Commit 7520a69

Browse files
committed
error,success方法兼容json请求
1 parent e74d9a1 commit 7520a69

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/Jump.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ protected function success($msg = '', string $url = null, $data = '', int $wait
4646
// 把跳转模板的渲染下沉,这样在 response_send 行为里通过getData()获得的数据是一致性的格式
4747
if ('html' == strtolower($type)) {
4848
$type = 'view';
49+
$response = Response::create($this->app->config->get('jump.dispatch_success_tmpl'), $type)->assign($result)->header($header);
50+
} else {
51+
$response = Response::create($result, $type)->header($header);
4952
}
5053

51-
$response = Response::create($this->app->config->get('jump.dispatch_success_tmpl'), $type)->assign($result)->header($header);
52-
5354
throw new HttpResponseException($response);
5455
}
5556

@@ -83,10 +84,11 @@ protected function error($msg = '', string $url = null, $data = '', int $wait =
8384

8485
if ('html' == strtolower($type)) {
8586
$type = 'view';
87+
$response = Response::create($this->app->config->get('jump.dispatch_error_tmpl'), $type)->assign($result)->header($header);
88+
} else {
89+
$response = Response::create($result, $type)->header($header);
8690
}
8791

88-
$response = Response::create($this->app->config->get('jump.dispatch_error_tmpl'), $type)->assign($result)->header($header);
89-
9092
throw new HttpResponseException($response);
9193
}
9294

@@ -123,7 +125,7 @@ protected function result($data, $code = 0, $msg = '', $type = '', array $header
123125
* @param array $with 隐式传参
124126
* @return void
125127
*/
126-
protected function redirect($url = '', $code = 302, $with = [])
128+
protected function redirect($url, $code = 302, $with = [])
127129
{
128130
$response = Response::create($url, 'redirect');
129131

0 commit comments

Comments
 (0)