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


PHP Response::setExpires方法代码示例

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


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

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

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

示例3: setExpires

 public function setExpires(\Datetime $datetime)
 {
     return parent::setExpires($datetime);
 }
开发者ID:mattvb91,项目名称:cphalcon,代码行数:4,代码来源:Response.php

示例4: cacheResponse

 /**
  * Cache the response 1 year (31536000 sec)
  */
 protected function cacheResponse(Response $response)
 {
     $response->setHeader('Cache-Control', 'public, max-age=31536000, s-maxage=31536000');
     $response->setExpires(new \DateTime('+1 year'));
     return $response;
 }
开发者ID:minhlaoleu,项目名称:phalcon-debugbar,代码行数:9,代码来源:AssetController.php


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