当前位置: 首页>>代码示例>>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;未经允许,请勿转载。