本文整理汇总了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());
}
}
示例2: response
/**
* @return Response
*/
public function response()
{
if ($this->__response === null) {
$this->__response = new Response();
$this->__response->setStatusCode(200);
}
return $this->__response;
}
示例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();
}
示例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;
}
示例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;
}
示例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);
}
示例7: setStatusCode
public function setStatusCode($code, $message = null)
{
if (is_null($message)) {
$message = $this->getResponseDescription($code);
}
parent::setStatusCode($code, $message);
return $message;
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}