本文整理汇总了PHP中Response::setData方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::setData方法的具体用法?PHP Response::setData怎么用?PHP Response::setData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Response
的用法示例。
在下文中一共展示了Response::setData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: call
/**
* @param Request $request
* @return Response
*/
public function call(Request $request)
{
// Create cURL
$ch = curl_init();
// Set-up URL
curl_setopt($ch, CURLOPT_URL, $request->getUrl());
// Set-up headers
$headers = $request->getHeaders();
array_walk($headers, function (&$item, $key) {
$item = "{$key}: {$item}";
});
curl_setopt($ch, CURLOPT_HTTPHEADER, array_values($headers));
// Set-up others
curl_setopt_array($ch, $request->getOpts());
// Receive result
$result = curl_exec($ch);
// Parse response
$response = new Response();
if ($result === FALSE) {
$response->setError(curl_strerror(curl_errno($ch)));
$response->setData(FALSE);
$response->setCode(curl_errno($ch));
$response->setHeaders(curl_getinfo($ch));
} else {
$response->setData(json_decode($result));
$response->setCode(curl_getinfo($ch, CURLINFO_HTTP_CODE));
$response->setHeaders(curl_getinfo($ch));
}
// Close cURL
curl_close($ch);
return $response;
}
示例2: actionGet
/**
* Returns a list of users.
* @return void
*/
public function actionGet()
{
$response = new Response();
$users = User::model()->findAll();
$data = array();
foreach ($users as $user) {
$data[] = $user->getResponseData();
}
$response->setStatus(Response::STATUS_OK);
$response->setData('list', $data);
$response->setData('total', count($users));
echo $response;
}
示例3: draw
public static function draw(\Exception $oExp)
{
@header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
$oResponse = new Response();
$oResponse->setData(array('success' => false, 'error' => $oExp->getMessage(), 'errorDetail' => array('type' => get_class($oExp), 'code' => $oExp->getCode())));
return $oResponse->flushJson();
}
示例4: jsonDeserialize
public static function jsonDeserialize($content)
{
$data = json_decode($content);
$keys = array_keys(json_decode($content, true));
$response = new Response();
foreach ($keys as $key) {
switch ($key) {
case 'status':
$response->setStatus($data->status);
break;
case 'data':
$response->setData($data->data);
break;
case 'error':
$response->setErrorMessage($data->error);
break;
case 'code':
$response->setErrorCode($data->code);
break;
case 'metadata':
foreach ((array) $data->metadata as $key => $value) {
$response->setMetadata($key, $value);
}
break;
}
}
return $response;
}
示例5: sendForBilling
function sendForBilling()
{
$response = new Response();
try {
$projectId = $this->input->post("project-id");
$amount = $this->input->post("project-bill-amount");
$billDoc = $this->input->post("bill-doc");
$project = $this->findById("Project", $projectId);
if ($project == null) {
throw new RuntimeException("Invalid Project..!");
}
$project->setStatus(Project::PROJECT_BILL);
$project->getWorkOrder()->setStatus(Workorder::STATUS_COMPLETED);
$project->getWorkOrder()->setApprovedBy($this->getLoggedInUser());
$bill = new Bill();
$bill->setAmount($amount);
$bill->setProject($project);
$bill->setCreated(new DateTime());
$bill->setStatus(Bill::STATUS_PENDING);
if ($billDoc != null && $billDoc != "") {
foreach ($billDoc as $file) {
$doc = new Document();
$doc->setName($file);
$doc->setCreated(new DateTime());
$bill->getBillDoc()->add($doc);
}
}
$this->save($bill);
$response->setData(Project::PROJECT_BILL);
} catch (Exception $e) {
$response->setStatus(false);
$response->setErrorMessage($e->getMessage());
}
$this->output->set_content_type('application/json')->set_output(json_encode($response));
}
示例6: approve
function approve()
{
$response = new Response();
try {
$projectId = $this->input->post("project-id");
$amount = floatval($this->input->post("project-bill-amount"));
$project = $this->findById("Project", $projectId);
if ($projectId == null) {
throw new RuntimeException("Invalid Request");
}
$availableAmount = $this->getAvailableFundAmountByScheme($project->getScheme()->getId());
if ($amount > floatval($availableAmount)) {
throw new RuntimeException("Insufficient Funds !");
}
$utilisedAmt = 0;
foreach ($this->getAvailableFunds($project->getScheme()) as $fund) {
/*if($fund->getAmount() == $fund->getUsedAmount()){
continue;
}*/
$reqAmt = $amount - $utilisedAmt;
$fundDetails = new FundDetails();
$fundDetails->setCreated(new DateTime());
$availableAmount = $fund->getAmount() - $fund->getUsedAmount();
if ($availableAmount >= $reqAmt) {
$fundDetails->setAmount($reqAmt);
$fund->setUsedAmount($fund->getUsedAmount() + $reqAmt);
$utilisedAmt = $amount;
} else {
if ($reqAmt <= $availableAmount) {
$fund->setUsedAmount($fund->getUsedAmount() + $reqAmt);
$fundDetails->setAmount($reqAmt);
$utilisedAmt = $utilisedAmt + $reqAmt;
} else {
$fund->setUsedAmount($fund->getUsedAmount() + $availableAmount);
$fundDetails->setAmount($availableAmount);
$utilisedAmt = $utilisedAmt + $availableAmount;
}
}
$fundDetails->setFund($fund);
$fundDetails->setProject($project);
$project->getFundDetails()->add($fundDetails);
if ($utilisedAmt == $amount) {
break;
}
}
$bill = $project->getBill();
$bill->setApprovedBy($this->getLoggedInUser());
$bill->setApprovedAmount($amount);
$bill->setStatus(Bill::STATUS_APPROVED);
$project->setStatus(Project::PROJECT_COMPLETED);
$this->save($project);
$response->setData(Bill::STATUS_APPROVED);
} catch (Exception $e) {
$response->setStatus(false);
$response->setErrorMessage($e->getMessage());
}
$this->output->set_content_type('application/json')->set_output(json_encode($response));
}
示例7: getAvailableFundsAmount
function getAvailableFundsAmount()
{
$response = new Response();
try {
$availableFunds = $this->getAvailableFundAmount(1);
$response->setData($availableFunds);
} catch (Exception $e) {
$response->setStatus(false);
$response->setErrorMessage($e->getMessage());
}
$this->output->set_content_type('application/json')->set_output(json_encode($response));
}
示例8: doQueryResponse
/**
* Execute an SQL select query and generate Response object
* @param string $type [description]
* @param string $sql SQL string to execute
* @param bool $isSingle Whether only one record should be returned
* @return Response $response Generated Response object
*/
public function doQueryResponse(Response $response, $sql, $type, $isSingle = false)
{
try {
// Execute the query
$result = $this->doQuery($sql, $isSingle);
// Save the data to the response object
$response->setData($type, $result);
} catch (\Rapi\PDOException $e) {
// Save the PDO error to the response
$response->setError($e->getCode(), $e->getMessage());
}
return $response;
}
示例9: select
public static function select($type, $sql, $params = array(), $single = false)
{
$response = new Response();
try {
$db = PDO::getConnection();
$stmt = $db->prepare($sql);
foreach ($params as $param => $paramValue) {
$stmt->bindParam($param, $paramValue[0], $paramValue[1]);
}
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_OBJ);
$db = null;
if ($single && is_array($result) && isset($result[0])) {
$result = $result[0];
}
$response->setData($type, $result);
} catch (\Exception $e) {
$response->setError($e->getCode(), $e->getMessage());
}
$response->output();
}
示例10: load
function load($id)
{
$response = new Response();
try {
$workOrder = $this->findById("Workorder", $id);
$comments = array();
foreach ($workOrder->getComments() as $cmt) {
$dto = new Commentdto();
$dto->setId($cmt->getId());
$dto->setComment($cmt->getComment());
$dto->setCreated(date_format($cmt->getCreated(), "d-M-Y"));
$dto->setCommentedBy($cmt->getCommentedBy()->getFirstName() . " " . $cmt->getCommentedBy()->getLastName());
array_push($comments, $dto);
}
$response->setData($comments);
} catch (Exception $e) {
$response->setStatus(false);
$response->setErrorMessage($e->getMessage());
}
$this->output->set_content_type('application/json')->set_output(json_encode($response));
}
示例11: getFundDetails
function getFundDetails($id = null)
{
$response = new Response();
try {
if ($id == null) {
throw new RuntimeException("Invalid Request..!");
}
$funds = parent::getFundDetails($id);
$fundArray = array();
foreach ($funds as $fund) {
$dto = new FundDetailsDto();
$dto->setAmount($fund->getAmount());
$dto->setProjectName($fund->getProject()->getName());
$dto->setFundAmount($fund->getFund()->getAmount());
array_push($fundArray, $dto);
}
$response->setData($fundArray);
} catch (Exception $e) {
$response->setStatus(false);
$response->setErrorMessage($e->getMessage());
}
$this->output->set_content_type('application/json')->set_output(json_encode($response));
}
示例12: sendCommand
public function sendCommand($command, $data = null)
{
$packet = $command;
if ($data) {
$packet .= ' ' . json_encode($data);
}
//echo "SENDING: [$packet]";
fwrite($this->fp, $packet . chr(0x4));
$res = $this->getResponse();
$response = new Response();
if ($res == 'ok') {
$response->setType('ok');
} else {
$p = strpos($res, '{');
if ($p > 0) {
$type = substr($res, 0, $p - 1);
$response->setType($type);
$json = substr($res, $p);
$data = json_decode($json, true);
$response->setData($data);
}
}
return $response;
}
示例13: listsSubscriber
/**
* Get Lists a Subscriber is Member of.
*
* <p><strong>Parameters:</strong><br/>
* [*subscriber_id] {integer} the Subscriber-ID.
* <p><strong>Returns:</strong><br/>
* Array of lists where the subscriber is assigned to.
* </p>
*/
public static function listsSubscriber($subscriber_id = 0)
{
$response = new Response();
if ($subscriber_id == 0) {
$subscriber_id = sprintf('%d', $_REQUEST['subscriber_id']);
}
$sql = 'SELECT * FROM ' . $GLOBALS['tables']['list'] . ' WHERE id IN
(SELECT listid FROM ' . $GLOBALS['tables']['listuser'] . ' WHERE userid=:subscriber_id) ORDER BY listorder;';
if (!is_numeric($subscriber_id) || empty($subscriber_id)) {
Response::outputErrorMessage('invalid call');
}
try {
$db = PDO::getConnection();
$stmt = $db->prepare($sql);
$stmt->bindParam('subscriber_id', $subscriber_id, PDO::PARAM_INT);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_OBJ);
$db = null;
$response->setData('Lists', $result);
$response->output();
} catch (\Exception $e) {
Response::outputError($e);
}
die(0);
}
示例14: simpleSuccessResponse
private function simpleSuccessResponse()
{
$response = new Response();
$response->setData(['result' => ['success' => true]]);
return $response;
}
示例15: formtokenGet
public static function formtokenGet()
{
$key = md5(time() . mt_rand(0, 10000));
Sql_Query(sprintf('insert into %s (adminid,value,entered,expires) values(%d,"%s",%d,date_add(now(),interval 1 hour))', $GLOBALS['tables']['admintoken'], $_SESSION['logindetails']['id'], $key, time()), 1);
$response = new Response();
$response->setData('formtoken', $key);
$response->output();
}