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


PHP Response::setContentType方法代码示例

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


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

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

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

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

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

示例5: __construct

 /**
  * PHPWebDevelopers\Api\Common\Http\Response constructor
  *
  * @param string $content
  * @param int $code
  * @param string $status
  */
 public function __construct($content = null, $code = null, $status = null)
 {
     parent::__construct($content, $code, $status);
     $request = new PhalconRequest();
     //@TODO Security fail!! Please do not go with this BETA
     $origin = $request->getHeader("ORIGIN");
     if (!empty($origin)) {
         parent::setHeader("Access-Control-Allow-Origin", $origin);
     }
     parent::setContentType(self::CONTENT_TYPE_JSON, self::CHARSET);
     parent::setHeader("Access-Control-Allow-Methods", self::ALLOW_METHODS);
     parent::setHeader("Access-Control-Allow-Headers", self::ALLOW_HEADERS);
     parent::setHeader("Access-Control-Allow-Credentials", self::ALLOW_CREDENTIALS);
 }
开发者ID:phpwebdevelopers,项目名称:api-common,代码行数:21,代码来源:Response.php

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

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

示例8: setContentType

 public function setContentType($contentType, $charset = null)
 {
     return parent::setContentType($contentType, $charset);
 }
开发者ID:mattvb91,项目名称:cphalcon,代码行数:4,代码来源:Response.php

示例9: download

 /**
  * Create an invoice download response.
  *
  * @param array $data
  */
 public function download(array $data)
 {
     $filename = $data['product'] . '_' . $this->date()->month . '_' . $this->date()->year . '.pdf';
     $response = new Response();
     $response->setHeader('Content-Description', 'File Transfer');
     $response->setHeader('Content-Disposition', 'attachment; filename="' . $filename . '"');
     $response->setStatusCode(200, 'OK');
     $response->setContent($this->pdf($data));
     $response->setContentType('application/pdf');
     return $response->send();
 }
开发者ID:duythien,项目名称:cashier,代码行数:16,代码来源:Invoice.php

示例10: response

 public function response(Response $response, $type, $quality = 90)
 {
     if (is_string($type) && isset(self::$typesConv[$type])) {
         $type = self::$typesConv[$type];
     }
     if ($type !== self::GIF && $type !== self::PNG && $type !== self::JPEG) {
         throw new \InvalidArgumentException("Unsupported image type.");
     }
     if ($type) {
         $this->getInternalImInstance()->setimageformat(self::$types[$type]);
     }
     if ($quality) {
         $this->getInternalImInstance()->setcompressionquality($quality > 1 ? $quality : round($quality * 100));
     }
     $response->setContentType(image_type_to_mime_type($type));
     $response->setContent((string) $this->getInternalImInstance());
     $response->send();
 }
开发者ID:kathynka,项目名称:Foundation,代码行数:18,代码来源:Image.php

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

示例12: api_pmail

function api_pmail($app, $msg_id)
{
    global $prop_tz, $server_tz, $user_id, $pm_deleted_by_receiver, $pm_deleted_by_sender;
    $response = new Response();
    $query = 'SELECT s.username as author, ss.username as recipient, p.subject, p.id as msg_id, p.sender, p.receiver,  CONVERT_TZ(p.created, \'' . $server_tz . '\', \'' . $prop_tz . ':00\') as created, p.body, s.id as sid, ss.id as rid, p.status, p.chars from confa_users s, confa_users ss, confa_pm p where s.id=p.sender and ss.id=p.receiver and p.id=' . $msg_id . ' and ' . '(p.sender=' . $user_id . ' and !(p.status & ' . $pm_deleted_by_sender . ') or p.receiver=' . $user_id . ' and !(p.status & ' . $pm_deleted_by_receiver . '))';
    $result = mysql_query($query);
    if (!$result) {
        $response->setStatusCode(400, 'Error');
        $response->setContentType('application/json');
        $response->setJsonContent(array('status' => 'ERROR', 'messages' => array(mysql_error())));
        return $response;
    }
    if (mysql_num_rows($result) != 0) {
        $row = mysql_fetch_assoc($result);
        $response->setContentType('application/json');
        $response->setJsonContent(array('id' => intval($row['msg_id']), 'status' => intval($row['status']), 'subject' => api_get_subject($row['subject']), 'author' => array('id' => intval($row['sid']), 'name' => $row['author']), 'recipient' => array('id' => intval($row['rid']), 'name' => $row['recipient']), 'created' => $row['created'], 'body' => array('html' => api_get_body($row['body']))));
    } else {
        $response->setStatusCode(404, 'Not Found')->sendHeaders();
        $response->setContentType('application/json');
        $response->setJsonContent(array('status' => 'ERROR', 'messages' => array('Message not found')));
    }
    return $response;
}
开发者ID:BGmot,项目名称:kitchen,代码行数:23,代码来源:index.php

示例13: sendAjax

 public function sendAjax($payload, $encode = true, array $headers = array())
 {
     $status = 200;
     $description = 'OK';
     $contentType = 'application/json';
     $content = $encode ? json_encode($payload) : $payload;
     $response = new Response();
     $response->setStatusCode($status, $description);
     $response->setContentType($contentType, 'UTF-8');
     $response->setContent($content);
     // Set the additional headers
     foreach ($headers as $key => $value) {
         $response->setHeader($key, $value);
     }
     $this->view->disable();
     return $response;
 }
开发者ID:skullab,项目名称:area51,代码行数:17,代码来源:Controller.php

示例14: render

 protected function render()
 {
     $format = $this->getFormat();
     $payload = $this->getPayload();
     $status = $this->getStatusCode();
     $description = $this->getResponseDescription($status);
     $headers = $this->getHeaders();
     switch ($format) {
         case 'json':
             $contentType = 'application/json';
             $content = json_encode($payload);
             break;
         case 'msgpack':
             $contentType = 'application/x-msgpack';
             $content = msgpack_pack($payload);
             break;
         default:
             $contentType = 'text/plain';
             $content = $payload;
             break;
     }
     $response = new Response();
     $response->setStatusCode($status, $description);
     $response->setContentType($contentType, 'UTF-8');
     // $response->setHeader('Access-Control-Allow-Origin', '*');
     $response->setHeader('Access-Control-Allow-Headers', 'X-Requested-With');
     $response->setContent($content);
     // Set the additional headers
     foreach ($headers as $key => $value) {
         $response->setHeader($key, $value);
     }
     $this->view->disable();
     return $response;
 }
开发者ID:JanOschii,项目名称:webird,代码行数:34,代码来源:RESTController.php


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