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