当前位置: 首页>>代码示例>>PHP>>正文


PHP Response::setData方法代码示例

本文整理汇总了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;
 }
开发者ID:r01261,项目名称:GopayInline,代码行数:36,代码来源:Curl.php

示例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;
 }
开发者ID:rBoost,项目名称:WRUD,代码行数:17,代码来源:UserController.php

示例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();
 }
开发者ID:sagarora77,项目名称:angular-filemanager-1,代码行数:7,代码来源:handler.php

示例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;
 }
开发者ID:chriscalifornia88,项目名称:min,代码行数:28,代码来源:Response.php

示例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));
 }
开发者ID:digvijaymohite,项目名称:e-tender,代码行数:35,代码来源:Workorders.php

示例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));
 }
开发者ID:digvijaymohite,项目名称:e-tender,代码行数:58,代码来源:Bills.php

示例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));
 }
开发者ID:digvijaymohite,项目名称:e-tender,代码行数:12,代码来源:Projects.php

示例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;
 }
开发者ID:grzchr15,项目名称:phplist-plugin-restapi,代码行数:20,代码来源:PdoEx.php

示例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();
 }
开发者ID:grzchr15,项目名称:phplist-plugin-restapi,代码行数:21,代码来源:common.php

示例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));
 }
开发者ID:digvijaymohite,项目名称:e-tender,代码行数:21,代码来源:Comments.php

示例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));
 }
开发者ID:digvijaymohite,项目名称:e-tender,代码行数:23,代码来源:Funds.php

示例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;
 }
开发者ID:joostfaassen,项目名称:vndb-client-php,代码行数:24,代码来源:Client.php

示例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);
 }
开发者ID:grzchr15,项目名称:phplist-plugin-restapi,代码行数:34,代码来源:lists.php

示例14: simpleSuccessResponse

 private function simpleSuccessResponse()
 {
     $response = new Response();
     $response->setData(['result' => ['success' => true]]);
     return $response;
 }
开发者ID:bhupendra-bhudia,项目名称:angular-filemanager,代码行数:6,代码来源:FileManagerApi.php

示例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();
 }
开发者ID:grzchr15,项目名称:phplist-plugin-restapi,代码行数:8,代码来源:Campaigns.php


注:本文中的Response::setData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。