本文整理汇总了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;
}
示例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;
}
示例3: setExpires
public function setExpires(\Datetime $datetime)
{
return parent::setExpires($datetime);
}
示例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;
}