-
Notifications
You must be signed in to change notification settings - Fork 0
/
R.php
74 lines (67 loc) · 1.44 KB
/
R.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
namespace elish;
use elish\helpers\StringHelper;
use elish\helpers\UrlHelper;
/**
* Json返回
*/
class R
{
/**
* 返回成功消息
* @param $msg
*/
public static function msg($msg)
{
header('Content-Type: application/json');
echo json_encode([
'code' => 0,
'msg' => $msg
]);
die;
}
/**
* 返回成功数据
* @param $data
*/
public static function data($data)
{
header('Content-Type: application/json');
echo json_encode([
'code' => 0,
'data' => $data
]);
die;
}
/**
* 返回成功消息
* @param string $msg
* @param int $code 状态码
*/
public static function error(string $msg, $code = 10000)
{
header('Content-Type: application/json');
echo json_encode([
'code' => $code,
'msg' => $msg
]);
die;
}
public static function redirect(string $url) {
if (is_array($url) || !StringHelper::startWith($url, 'http')) {
$url = UrlHelper::create($url);
}
header("location: {$url}");
die;
}
/**
* 返回上一页
*/
public static function goback(){
if(isset($_SERVER['HTTP_REFERER'])){
self::redirect($_SERVER['HTTP_REFERER']);
}else{
die('<script>history.go(-1);</script>');
}
}
}