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


PHP Response::setJsonContent方法代码示例

本文整理汇总了PHP中Phalcon\Http\Response::setJsonContent方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::setJsonContent方法的具体用法?PHP Response::setJsonContent怎么用?PHP Response::setJsonContent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Phalcon\Http\Response的用法示例。


在下文中一共展示了Response::setJsonContent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: renderAJAX

 /**
  * Renders the uncaught exception for AJAX consumption.
  * 
  * @param  Phalcon\Http\Response  $response
  * @param  \Exception $exceptio
  * @return void
  */
 protected function renderAJAX(Response $response, Exception $exception)
 {
     if ($this->config->debug) {
         $response->setJsonContent(['_exception' => $exception->getMessage() . ': ' . $exception->getTraceAsString()]);
     } else {
         $response->setJsonContent(['status' => false]);
     }
 }
开发者ID:halfbakedsneed,项目名称:phalcore,代码行数:15,代码来源:Handler.php

示例2: indexAction

 public function indexAction($name)
 {
     $response = new Response();
     $this->getData($name);
     if (!$this->result) {
         $response->setJsonContent(array('status' => 'NOT-FOUND'));
     } else {
         $response->setJsonContent(array('status' => 'FOUND', 'data' => $this->result));
     }
     return $response;
 }
开发者ID:a3aremba,项目名称:phptest,代码行数:11,代码来源:IndexController.php

示例3: getContent

function getContent($robots)
{
    //Create a response
    $response = new Response();
    $data = array();
    foreach ($robots as $robot) {
        array_push($data, $robot);
    }
    if ($data == false || count($data) == 0) {
        $response->setJsonContent(array('status' => 'NOT-FOUND'));
    } else {
        $response->setJsonContent(array('status' => 'FOUND', 'data' => $data));
    }
    return $response;
}
开发者ID:rizkix,项目名称:phalconrest,代码行数:15,代码来源:content.php

示例4: jsonResponse

 protected function jsonResponse($data)
 {
     $response = new Response();
     $response->setContentType('application/json', 'UTF-8');
     $response->setJsonContent($data);
     return $response;
 }
开发者ID:caiofralmeida,项目名称:soccer-company-event,代码行数:7,代码来源:BaseController.php

示例5: returnResult

 public function returnResult($result, $errorMessage = null)
 {
     $response = new Response();
     $result = ['result' => $result, 'status' => $errorMessage === null ? self::SUCCESS_RESPONSE : self::FAILED_RESPONSE, 'error_message' => (string) $errorMessage];
     $response->setJsonContent($result);
     return $response;
 }
开发者ID:boorlyk,项目名称:friendsApi,代码行数:7,代码来源:RestController.php

示例6: sendResult

 /**
  * 发送数据
  * @param mixed $result
  */
 private static function sendResult($result)
 {
     $response = new Response();
     $response->setHeader('Content-Type', 'application/json; charset=UTF-8');
     $response->setHeader('Access-Control-Allow-Origin', '*');
     $response->setJsonContent($result);
     $response->send();
     exit;
 }
开发者ID:huxiaohe,项目名称:api-framework,代码行数:13,代码来源:ResponseApi.php

示例7: setJsonContent

 public function setJsonContent($content, $jsonOptions = 0, $depth = 512)
 {
     parent::setJsonContent($content, $jsonOptions, $depth);
     $this->setHeader('Access-Control-Allow-Origin', '*');
     $this->setHeader('Access-Control-Allow-Methods', 'GET,HEAD,PUT,PATCH,POST,DELETE');
     $this->setHeader('Access-Control-Allow-Headers', 'Content-Type, X-Requested-With, Authorization');
     $this->setHeader('E-Tag', md5($this->getContent()));
     $this->setContentType('application/json');
 }
开发者ID:Thyoity,项目名称:phalcon-rest,代码行数:9,代码来源:Response.php

示例8: sendResponse

 public function sendResponse()
 {
     if ($this->di->has('view')) {
         $this->di->get('view')->disable();
     }
     $response = new Response();
     $response->setContentType('application/json', 'utf8');
     $response->setJsonContent($this->getResponse());
     $response->send();
 }
开发者ID:mzf,项目名称:phalcon-datatables,代码行数:10,代码来源:DataTable.php

示例9: response

 public function response($data = array(), $status = 200, $token = null)
 {
     $response = new Response();
     $response->setStatusCode($status);
     $response->setContent(!empty($this->_statuses[$status]) ? $this->_statuses[$status] : null);
     $response->setHeader('Content-type', 'application/json');
     $response->setHeader('api-version', '1.0');
     $response->setHeader('singou-token', $token);
     $response->setJsonContent($data);
     return $response;
 }
开发者ID:zhuo-jiejie,项目名称:rest-server,代码行数:11,代码来源:BaseController.php

示例10: voteAction

 /**
  * Votes for a poll option
  *
  * @param int $id     Post ID
  * @param int $option Option ID
  * @return Response
  */
 public function voteAction($id = 0, $option = 0)
 {
     $response = new Response();
     if (!$this->checkTokenGetJson('post-' . $id)) {
         $csrfTokenError = ['status' => 'error', 'message' => 'This post is outdated. Please try to vote again.'];
         return $response->setJsonContent($csrfTokenError);
     }
     if (!($post = Posts::findFirstById($id))) {
         $contentNotExist = ['status' => 'error', 'message' => 'Poll does not exist'];
         return $response->setJsonContent($contentNotExist);
     }
     if (!($user = Users::findFirstById($this->session->get('identity')))) {
         $contentlogIn = ['status' => 'error', 'message' => 'You must log in first to vote'];
         return $response->setJsonContent($contentlogIn);
     }
     if (!($option = PostsPollOptions::findFirstById($option))) {
         $optionNotFound = ['status' => 'error', 'message' => 'Please select one option from the list below'];
         return $response->setJsonContent($optionNotFound);
     }
     if ($post->isParticipatedInPoll($user->id)) {
         $contentAlreadyVote = ['status' => 'error', 'message' => 'You have already voted this post'];
         return $response->setJsonContent($contentAlreadyVote);
     }
     $pollVote = new PostsPollVotes();
     $pollVote->posts_id = $post->id;
     $pollVote->users_id = $user->id;
     $pollVote->options_id = $option->id;
     if (!$pollVote->save()) {
         foreach ($pollVote->getMessages() as $message) {
             /** @var \Phalcon\Mvc\Model\Message $message */
             $contentError = ['status' => 'error', 'message' => $message->getMessage()];
             return $response->setJsonContent($contentError);
         }
     }
     if ($post->users_id != $user->id) {
         $post->user->increaseKarma(Karma::SOMEONE_DID_VOTE_MY_POLL);
         $user->increaseKarma(Karma::VOTE_ON_SOMEONE_ELSE_POLL);
     }
     if (!$post->save()) {
         foreach ($post->getMessages() as $message) {
             /** @var \Phalcon\Mvc\Model\Message $message */
             $contentErrorSave = ['status' => 'error', 'message' => $message->getMessage()];
             return $response->setJsonContent($contentErrorSave);
         }
     }
     $viewCache = $this->getDI()->getShared('viewCache');
     $viewCache->delete('post-' . $post->id);
     $viewCache->delete('poll-votes-' . $post->id);
     $viewCache->delete('poll-options-' . $post->id);
     $contentOk = ['status' => 'OK'];
     return $response->setJsonContent($contentOk);
 }
开发者ID:phalcon,项目名称:forum,代码行数:59,代码来源:PollsController.php

示例11: deleteAction

 /**
  * Method Http accept: DELETE
  */
 public function deleteAction()
 {
     $modelName = $this->modelName;
     $model = $modelName::findFirst($this->id);
     //delete if exists the object
     if ($model != false) {
         if ($model->delete() == true) {
             $this->response->setJsonContent(array('status' => "OK"));
         } else {
             $this->response->setStatusCode(409, "Conflict");
             $errors = array();
             foreach ($model->getMessages() as $message) {
                 $errors[] = $this->language[$message->getMessage()] ? $this->language[$message->getMessage()] : $message->getMessage();
             }
             $this->response->setJsonContent(array('status' => "ERROR", 'messages' => $errors));
         }
     } else {
         $this->response->setStatusCode(409, "Conflict");
         $this->response->setJsonContent(array('status' => "ERROR", 'messages' => array("O elemento não existe")));
     }
     return $this->response;
 }
开发者ID:GeraldoSilva,项目名称:API-REST-PHALCON-PHP,代码行数:25,代码来源:RestController.php

示例12: res

function res($req, $res)
{
    $response = new Response();
    $response->setContentType('application/json');
    switch ($req) {
        case 'INDEX':
            if ($res == false) {
                $response->setJsonContent(array('status' => 'NOT-FOUND'));
            } else {
                $response->setJsonContent(array('status' => 'FOUND', 'data' => $res));
            }
            break;
        case 'READ':
            if ($res == false) {
                $response->setJsonContent(array('status' => 'NOT-FOUND'));
            } else {
                $response->setJsonContent(array('status' => 'FOUND', 'data' => $res));
            }
            break;
        default:
            if ($res->success() == true) {
                switch ($req) {
                    case 'CREATE':
                        $response->setStatusCode(201, 'Created');
                        break;
                    case 'UPDATE':
                        $response->setStatusCode(200, 'Update Successfully');
                        break;
                    case 'DELETE':
                        $response->setStatusCode(205, 'Delete Successfully');
                        break;
                }
                $response->setJsonContent(array('status' => 'OK'));
            } else {
                $response->setStatusCode(409, 'Conflict');
                $errors = array();
                foreach ($res->getMessages() as $message) {
                    $errors[] = $message->getMEssage();
                }
                $response->setJsonContent(array('status' => 'ERROR', 'messages' => $errors));
            }
            break;
    }
    return $response;
}
开发者ID:kobabasu,项目名称:micro-project,代码行数:45,代码来源:users.php

示例13: joinAction

 function joinAction($id)
 {
     $response = new Response();
     if (!$id) {
         $error = array("status" => "error", "message" => "No id was specified.");
         return $response->setJsonContent($error);
     }
     $league = Leagues::findFirst("id = '{$id}'");
     if (!$league) {
         $error = array("status" => "error", "message" => "The league does not exist.");
         return $response->setJsonContent($error);
     }
     $uid = $this->session->get('user');
     $lid = $league->id;
     $userLeague = UserLeagues::findFirst("lid = '{$lid}' AND uid = '{$uid}'");
     if ($userLeague) {
         $error = array("status" => "error", "message" => "You are already a member of this league.");
         return $response->setJsonContent($error);
     }
     $userLeague = new UserLeagues();
     $userLeague->uid = $uid;
     $userLeague->lid = $lid;
     if (!$userLeague->create()) {
         $error = array("status" => "error", "message" => "There was an error creating the league membership.");
         return $response->setJsonContent($error);
     }
     $success = array("status" => "success");
     return $response->setJsonContent($success);
 }
开发者ID:JApfel,项目名称:MarketDraft,代码行数:29,代码来源:LeaguesController.php

示例14: Response

            } else {
                throw new \Exception('É necessário estar registrado no sistema para realizar requisições2.', StatusCodes::NAO_AUTORIZADO);
            }
        } else {
            return true;
        }
    }
});
$app->setEventsManager($eventsManager);
$app->error(function ($exception) {
    $response = new Response();
    $response->setContentType('application/json', 'UTF-8');
    $response->setStatusCode($exception->getCode());
    $response->setHeader("Access-Control-Allow-Origin", "*");
    $response->setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS, PUT, DELETE");
    $response->setHeader("Access-Control-Allow-Headers", "Authorization,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type");
    $response->setJsonContent(['error' => $exception->getMessage()]);
    $response->send();
    return false;
});
$app->after(function () use($app) {
    $return = $app->getReturnedValue();
    if ($return instanceof Response) {
        $return->send();
    } else {
        $response = new Response();
        $response->setContentType('application/json', 'UTF-8');
        $response->setJsonContent($return);
        $response->send();
    }
});
开发者ID:anderson-slompo,项目名称:wsGerProj,代码行数:31,代码来源:app.php

示例15: response

 /**
  * @param array $data
  * @param int $status
  * @return Response
  */
 public function response($data = array(), $status = 200)
 {
     $response = new Response();
     $response->setStatusCode($status);
     $response->setContent(!empty($this->_statuses[$status]) ? $this->_statuses[$status] : null);
     $response->setHeader('Content-type', 'application/json');
     $response->setHeader('api-version', '1.0');
     $devDebug = $this->request->get('devDebug');
     if (true == $devDebug) {
         $profiles = $this->getDI()->get('profiler')->getProfiles();
         foreach ($profiles as $profile) {
             $data['SQL Statement'] = $profile->getSQLStatement();
             $data['Start Time'] = $profile->getInitialTime();
             $data['Final Time'] = $profile->getFinalTime();
             $data['Total Elapsed Time'] = $profile->getTotalElapsedSeconds();
         }
     }
     $response->setJsonContent($data, JSON_PRETTY_PRINT);
     return $response;
 }
开发者ID:junyichiu,项目名称:Phalcon-RESTful-Server,代码行数:25,代码来源:BaseController.php


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