當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Response::setStatusCode方法代碼示例

本文整理匯總了PHP中Phalcon\Http\Response::setStatusCode方法的典型用法代碼示例。如果您正苦於以下問題:PHP Response::setStatusCode方法的具體用法?PHP Response::setStatusCode怎麽用?PHP Response::setStatusCode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Phalcon\Http\Response的用法示例。


在下文中一共展示了Response::setStatusCode方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: uploadAction

 public function uploadAction()
 {
     $this->mediaModel = new Media();
     if ($this->request->hasFiles() == true) {
         $uploads = $this->request->getUploadedFiles();
         $this->view->disable();
         $uploaded = true;
         foreach ($uploads as $fileObj) {
             if (!$this->mediaModel->initFile($fileObj)) {
                 $uploaded = false;
             }
         }
         $response = new Response();
         if (!$uploaded) {
             $error = implode("\n", $this->mediaModel->getError());
             $response->setStatusCode(406, $error);
         } else {
             $response->setStatusCode(200, "Success");
         }
         return $response;
     } else {
         $this->assets->addCss('/core/assets/css/dropzone.css', false);
         $this->assets->addJs('/core/assets/js/dropzone.js', false);
         $this->view->acceptExt = implode(",", $this->constants->mediaAcceptFilesExt());
     }
 }
開發者ID:kjmtrue,項目名稱:phanbook,代碼行數:26,代碼來源:MediaController.php

示例2: response

 /**
  * @return Response
  */
 public function response()
 {
     if ($this->__response === null) {
         $this->__response = new Response();
         $this->__response->setStatusCode(200);
     }
     return $this->__response;
 }
開發者ID:serus22,項目名稱:phalconz,代碼行數:11,代碼來源:BaseController.php

示例3: send

 /**
  * 發送響應消息
  *
  * @param   string  $message    響應信息
  * @param   int     $status     響應狀態碼
  */
 public static function send($message = '', $status = 200)
 {
     if (self::$response === null) {
         self::init();
     }
     self::$response->setStatusCode(intval($status));
     self::$response->setContent(strval($message));
     self::$response->send();
 }
開發者ID:q-phalcon,項目名稱:kernel,代碼行數:15,代碼來源:QpResponse.php

示例4: download

 public function download($id)
 {
     $anexo = Anexo::findFirst($id);
     $response = new Response();
     if ($anexo) {
         $response->setStatusCode(StatusCodes::OK);
         $response->setFileToSend($anexo->getCaminho(), $anexo->getOriginal());
     } else {
         $response->setStatusCode(StatusCodes::NAO_ENCONTRADO);
     }
     return $response;
 }
開發者ID:anderson-slompo,項目名稱:wsGerProj,代碼行數:12,代碼來源:DownloadController.php

示例5: accessToken

 /**
  * Exchange a request token for an access token.
  * The exchange is only succesful iff the request token has been authorized.
  *
  * Never returns, calls exit() when token is exchanged or when error is returned.
  */
 public function accessToken()
 {
     try {
         $this->verifyRequest(self::TOKEN_TYPE_REQUEST);
         $options = array();
         $ttl = $this->request->get('xoauth_token_ttl');
         if ($ttl) {
             $options['token_ttl'] = $ttl;
         }
         $verifier = $this->request->get('oauth_verifier');
         if ($verifier) {
             $options['verifier'] = $verifier;
         }
         $store = $this->store;
         $token = $store->exchangeConsumerRequestForAccessToken($this->request->getParam('oauth_token', true), $options);
         /** @var /Foundation/Oauth/Secrets $token */
         $content = array("oauth_token" => $token->token, "oauth_token_secret" => $token->token_secret);
         if ($token->ttl) {
             $content['xoauth_token_ttl'] = $token->ttl;
         }
         $this->response->setContent(http_build_query($content));
         $this->response->setStatusCode(200, "");
         $this->response->setContentType("application/x-www-form-urlencoded");
     } catch (OauthException $e) {
         $this->response->setStatusCode(401, "OAuth Verification Failed: " . $e->getMessage());
     }
     return $this->response;
 }
開發者ID:kathynka,項目名稱:Foundation,代碼行數:34,代碼來源:OauthService.php

示例6: __construct

 public function __construct()
 {
     parent::__construct(false);
     static::$runningUnitTest = Config::runningUnitTest();
     // @codeCoverageIgnoreStart
     if ($this->_sitePathPrefix = Config::get('app.site_path')) {
         $this->_uriSource = self::URI_SOURCE_GET_URL;
         $this->_sitePathLength = strlen($this->_sitePathPrefix);
     }
     // @codeCoverageIgnoreEnd
     $this->removeExtraSlashes(true);
     $routes = is_file($file = $_SERVER['PHWOOLCON_ROOT_PATH'] . '/app/routes.php') ? include $file : [];
     is_array($routes) and $this->addRoutes($routes);
     $this->cookies = static::$di->getShared('cookies');
     $this->response = static::$di->getShared('response');
     $this->response->setStatusCode(200);
 }
開發者ID:phwoolcon,項目名稱:phwoolcon,代碼行數:17,代碼來源:Router.php

示例7: setStatusCode

 public function setStatusCode($code, $message = null)
 {
     if (is_null($message)) {
         $message = $this->getResponseDescription($code);
     }
     parent::setStatusCode($code, $message);
     return $message;
 }
開發者ID:Archcry,項目名稱:PhalconApiBase,代碼行數:8,代碼來源:Response.php

示例8: 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

示例9: respond

 /**
  * Send response to client
  */
 public function respond($data, $status = 200)
 {
     $response = new Response();
     $response->setContentType('application/json');
     $response->setStatusCode($status);
     $data = $data instanceof SimpleResultSet ? $data->toArray() : $data;
     $response->setContent(json_encode($data));
     $response->send();
 }
開發者ID:bilna-dev,項目名稱:monitoring-tools,代碼行數:12,代碼來源:Restable.php

示例10: debugEnvAction

 public function debugEnvAction()
 {
     //var_dump($_SERVER['REDIRECT_URL']);die();
     $actual_route = $_SERVER['REDIRECT_URL'];
     $response = new Response();
     $response->setStatusCode(404, "Not Found");
     $response->setContent("Sorry, the route: <b>" . $actual_route . " </b> doesn't exist");
     $response->send();
     return $response;
 }
開發者ID:leyriel,項目名稱:allocuisto_dev,代碼行數:10,代碼來源:NotFoundController.php

示例11: response

 /**
  * 設置響應狀態碼和響應資源
  *
  * 當API控製器發送響應時調用此方法
  *
  * @param integer $statusCode 資源響應狀態碼, 本狀態碼與HTTP狀態碼完全吻合
  * @param string  $explain    狀態描述
  * @param mixed   $resource   資源
  */
 protected function response($statusCode, $explain, $resource = '')
 {
     $this->response = new Response();
     $this->response->setStatusCode($statusCode, $explain);
     if (is_array($resource)) {
         $this->resource = (object) $resource;
     } else {
         $this->resource = $resource;
     }
 }
開發者ID:sujinw,項目名稱:passport,代碼行數:19,代碼來源:BaseController.php

示例12: 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

示例13: ajaxResponse

 protected function ajaxResponse($content, $toJson = true)
 {
     if (!$this->request->isAjax()) {
         $content = json_encode(['error' => "Invalid Request"]);
     } elseif ($toJson) {
         $content = json_encode($content);
     }
     $response = new Response();
     $response->setStatusCode(200, 'OK');
     $response->setContentType('application/json', 'UTF-8');
     $response->setContent($content);
     return $response;
 }
開發者ID:brianwalden,項目名稱:sas,代碼行數:13,代碼來源:BaseController.php

示例14: process

 /**
  * Выполняет все плагины по цепочке
  * 
  * @param \Phalcon\Http\Request $request
  * @return string
  */
 public function process(Request $request)
 {
     $response = new Response();
     $pluginResult = new PluginResult();
     foreach ($this->_arPlugins as $plugin) {
         $pluginResult = $plugin->process($request, $pluginResult);
         if ($pluginResult->terminate) {
             break;
         }
     }
     if ($pluginResult->error) {
         $response->setStatusCode($pluginResult->errorCode, $pluginResult->errorMessage);
         $response->setContent($pluginResult->errorMessage);
         return $response;
     } else {
         $response->setStatusCode(200, "OK");
     }
     $callback = $request->getQuery('callback');
     $result = '';
     if ($callback) {
         $response->setHeader('Content-Type', 'application/javascript');
         $result .= $callback . '(';
     } else {
         $response->setHeader('Content-Type', 'application/json');
     }
     $result .= json_encode(array('searchContext' => $pluginResult->searchContext, 'result' => $pluginResult->result));
     if ($callback) {
         $result .= ');';
     }
     if ($pluginResult->fileToSend) {
         $response->setFileToSend($pluginResult->fileToSend, 'data.txt');
     } else {
         $response->setContent($result);
     }
     return $response;
 }
開發者ID:olegabr,項目名稱:kladrapi,代碼行數:42,代碼來源:ApiService.php

示例15: getAction

 /**
  * Returs the raw comment as it as edited
  *
  * @param $id
  *
  * @return Response
  */
 public function getAction($id)
 {
     $response = new Response();
     $usersId = $this->session->get('identity');
     if (!$usersId) {
         $response->setStatusCode('401', 'Unauthorized');
         return $response;
     }
     $parametersReply = array('id = ?0', 'bind' => array($id));
     $postReply = PostsReplies::findFirst($parametersReply);
     if ($postReply) {
         $data = array('status' => 'OK', 'id' => $postReply->id, 'comment' => $postReply->content);
     } else {
         $data = array('status' => 'ERROR');
     }
     $response->setJsonContent($data);
     return $response;
 }
開發者ID:Rudianasaja,項目名稱:forum,代碼行數:25,代碼來源:RepliesController.php


注:本文中的Phalcon\Http\Response::setStatusCode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。