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


PHP Response::setHeader方法代碼示例

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


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

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

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

示例3: rawAction

 public function rawAction()
 {
     $plain_response = new Response();
     $plain_response->setHeader("Content-Type", "text/plain");
     $plain_response->setContent($this->paste->content);
     return $plain_response;
 }
開發者ID:carriercomm,項目名稱:Phaste,代碼行數:7,代碼來源:ViewController.php

示例4: __construct

 public function __construct()
 {
     parent::__construct();
     parent::setHeader('Access-Control-Allow-Origin', '*');
     parent::setHeader('Access-Control-Allow-Headers', 'X-Requested-With');
     $this->setStatusCode(self::DEFAULT_STATUS_CODE);
 }
開發者ID:Archcry,項目名稱:PhalconApiBase,代碼行數:7,代碼來源:Response.php

示例5: responseJson

 /**
  * 創建JSON格式的Http響應
  *
  * @param integer $status   狀態碼, 該狀態碼采用HTTP狀態碼近似, 但為數據輸出. 該Http響應的狀態碼始終為200
  * @param string  $explain  狀態描述
  * @param array   $data     響應數據
  * @return Response
  */
 public function responseJson($status = 200, $explain = '', $data = array())
 {
     $response = new Response();
     $response->setStatusCode(200, 'OK');
     $response->setHeader("Content-Type", "text/json");
     $contents = array('statusCode' => $status, 'explain' => $explain, 'original_val' => isset($_GET['original_val']) ? $_GET['original_val'] : $this->request->getPost('original_val', null, ''), 'data' => (object) $data);
     $response->setContent(json_encode($contents, true));
     return $response;
 }
開發者ID:sujinw,項目名稱:passport,代碼行數:17,代碼來源:BaseController.php

示例6: handleAction

 public function handleAction()
 {
     $debugbar = $this->debugbar;
     $debugbar->enable();
     $openHandler = new OpenHandler($debugbar);
     $data = $openHandler->handle(null, false, false);
     $response = new Response($data, 200);
     $response->setHeader('Content-Type', 'application/json');
     return $response;
 }
開發者ID:minhlaoleu,項目名稱:phalcon-debugbar,代碼行數:10,代碼來源:OpenHandlerController.php

示例7: send

 /**
  * 向Client發送響應的資源
  */
 public function send()
 {
     if (is_array($this->resource) || is_object($this->resource)) {
         $this->response->setHeader('Content-Type', 'text/json');
         $this->response->setContent(json_encode($this->resource, true));
     } else {
         $this->response->setContent($this->resource);
     }
     $this->response->send();
 }
開發者ID:sujinw,項目名稱:passport,代碼行數:13,代碼來源:BaseController.php

示例8: toResponse

 public function toResponse()
 {
     $response = new Response($this->getMessage(), $this->getCode());
     $headers = $this->getHeaders();
     foreach ($headers as $name => $value) {
         if (is_numeric($name)) {
             list($name, $value) = explode(':', $value);
         }
         $response->setHeader(trim($name), trim($value));
     }
     return $response;
 }
開發者ID:phwoolcon,項目名稱:phwoolcon,代碼行數:12,代碼來源:HttpException.php

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

示例10: indexAction

 /**
  * 返回所有國家
  * @api /country/
  * @return [type] [description]
  */
 public function indexAction()
 {
     $countries = Countries::find();
     $requestCnt = array_pick($this->request->getAcceptableContent(), 'accept', true);
     if (in_array('application/json', $requestCnt)) {
         $response = new Response();
         $response->setHeader("Content-Type", "application/json");
         echo json_encode($countries->toArray());
         $this->view->disable();
     } else {
         $this->view->setVar('countries', $countries);
         $this->view->setVar('title', '世界國家');
     }
 }
開發者ID:gamelife1314,項目名稱:city,代碼行數:19,代碼來源:CountryController.php

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

示例12: listAction

 public function listAction()
 {
     $response = new Response();
     $response->setHeader('Content-Type', 'application/json');
     $datas = array();
     if ($this->request->get('active') == '1') {
         $profiles = Profiles::find(array("active = 'Y'", "columns" => 'id, name, active'));
     } else {
         $profiles = Profiles::find(array("columns" => 'id, name, active'));
     }
     foreach ($profiles as $profile) {
         $datas[] = $profile;
     }
     $response->setJsonContent($datas);
     return $response;
 }
開發者ID:robinxiong,項目名稱:cmsdb,代碼行數:16,代碼來源:ProfilesController.php

示例13: indexAction

    /**
     * Generate the website robots.txt
     */
    public function indexAction()
    {
        $response = new Response();
        $expireDate = new \DateTime();
        $expireDate->modify('+1 month');
        $response->setExpires($expireDate);
        $response->setHeader('Content-Type', "text/plain; charset=UTF-8");
        $baseUrl = rtrim($this->config->site->url, '/');
        $content = <<<EOL
User-agent: *
Allow: /
Sitemap: {$baseUrl}/sitemap
EOL;
        $response->setContent($content);
        return $response;
    }
開發者ID:huoybb,項目名稱:forum,代碼行數:19,代碼來源:RobotsController.php

示例14: rssAction

 /**
  * Handles the RSS action. Constructs the rss feed of the latest posts. The
  * number of posts to return is stored in the configuration section
  *
  * @return Response
  */
 public function rssAction()
 {
     $feed = new RSS2();
     $feed->setEncoding('UTF-8');
     $feed->setTitle($this->config->rss->title);
     $feed->setDescription($this->config->rss->description);
     $feed->setLink($this->getFullUrl());
     $posts = $this->finder->getLatest(1);
     foreach ($posts as $post) {
         $feedItem = new Item();
         $feedItem->setTitle($post->getTitle());
         $feedItem->setLink($this->getFullUrl('/post/' . $post->getSlug()));
         $feedItem->setDescription($post->getContent());
         $feedItem->setDate($post->getDate());
         $feed->addItem($feedItem);
     }
     $response = new Response();
     $response->setHeader('Content-Type', 'application/xml');
     $response->setContent($feed->generateFeed());
     return $response;
 }
開發者ID:aisuhua,項目名稱:blog-1,代碼行數:27,代碼來源:PostsController.php

示例15: indexAction

 /**
  * Generate the website sitemap
  */
 public function indexAction()
 {
     $response = new Response();
     $expireDate = new \DateTime();
     $expireDate->modify('+1 day');
     $response->setExpires($expireDate);
     $response->setHeader('Content-Type', "application/xml; charset=UTF-8");
     $sitemap = new \DOMDocument("1.0", "UTF-8");
     $urlset = $sitemap->createElement('urlset');
     $urlset->setAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
     $urlset->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
     $baseUrl = $this->config->site->url;
     $url = $sitemap->createElement('url');
     $url->appendChild($sitemap->createElement('loc', $baseUrl));
     $url->appendChild($sitemap->createElement('changefreq', 'daily'));
     $url->appendChild($sitemap->createElement('priority', '1.0'));
     $urlset->appendChild($url);
     $karmaSql = 'number_views + ' . '((IF(votes_up IS NOT NULL, votes_up, 0) - IF(votes_down IS NOT NULL, votes_down, 0)) * 4) + ' . 'number_replies';
     $parametersPosts = ['conditions' => 'deleted != 1', 'columns' => "id, slug, modified_at, {$karmaSql} AS karma", 'order' => 'karma DESC'];
     $posts = Posts::find($parametersPosts);
     $parametersKarma = ['column' => $karmaSql, 'conditions' => 'deleted != 1'];
     $karma = Posts::maximum($parametersKarma);
     $modifiedAt = new \DateTime();
     $modifiedAt->setTimezone(new \DateTimeZone('UTC'));
     foreach ($posts as $post) {
         $modifiedAt->setTimestamp($post->modified_at);
         $postKarma = $post->karma / ($karma + 100);
         $url = $sitemap->createElement('url');
         $href = trim($baseUrl, '/') . '/discussion/' . $post->id . '/' . $post->slug;
         $url->appendChild($sitemap->createElement('loc', $href));
         $valuePriority = $postKarma > 0.7 ? sprintf("%0.1f", $postKarma) : sprintf("%0.1f", $postKarma + 0.25);
         $url->appendChild($sitemap->createElement('priority', $valuePriority));
         $url->appendChild($sitemap->createElement('lastmod', $modifiedAt->format('Y-m-d\\TH:i:s\\Z')));
         $urlset->appendChild($url);
     }
     $sitemap->appendChild($urlset);
     $response->setContent($sitemap->saveXML());
     return $response;
 }
開發者ID:huoybb,項目名稱:forum,代碼行數:42,代碼來源:SitemapController.php


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