ResponseMessage.class.php
1.53 KB
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
75
<?php
require_once dirname(__FILE__).'/ResponseStatus.class.php';
require_once dirname(__FILE__).'/ResponseAjaxResponse.class.php';
/**
* ajax回应类
*
*/
class ResponseMessage
{
/**
* 状态对象
* @var object
*/
private $mStatus;
/**
* 前端结果对象
* @var object
*/
private $mAjaxResponse;
/**
* 初始化函数
*/
public function __construct()
{
$this->mStatus = new ResponseStatus();
$this->mAjaxResponse = new ResponseAjaxResponse();
}
/**
* 设置ajaxResponse的data数据函数
*
* @param $data
* @param $content
* @param $code
*/
public function setData($data, $content = '', $code = AJAX_RESPONSE_STATUS_OK)
{
if(isset($data))
{
$this->mAjaxResponse->data = $data;
$this->mStatus->content = $content;
$this->mStatus->code = $code;
}
}
/**
* 设置错误信息函数
*
* @param string $errorMsg
* @param int $code
*/
public function setError($errorMsg, $code = AJAX_RESPONSE_STATUS_FAIL)
{
if(isset($errorMsg))
{
$this->mStatus->content = $errorMsg;
$this->mStatus->code = $code;
$this->mAjaxResponse->data = null;
}
}
/**
* 返回结果
*
* @return object
*/
public function getResult()
{
$this->mAjaxResponse->status = $this->mStatus;
return $this->mAjaxResponse;
}
}
?>