脚本宝典收集整理的这篇文章主要介绍了如何为CakePHP创建站点地图?,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
在你的控制器中:
public $components = array('RequestHandler'); public function sitemap() { Configure::write('debug',0); $articles = $this->Article->getSitemapInformation(); $this->set(compact('articles')); $this->RequestHandler->respondAs('XMl'); }
你的“文章”模型:
public function getSitemapInformation() { return $this->find('all',array(/* your query here */)); }
视图:
<urlset xMLns="http://www.sitemaps.org/schemas/sitemap/0.9"> <?PHP foreach ($articles as $article): ?> <url> <loc><?PHP echo Router::url(/* generate the URLs here */); ?></loc> <lastmod><?PHP echo $time->toAtom(/* last update time here */); ?></lastmod> <changefreq>weekly</changefreq> </url> <?PHP enDForeach; ?> </urlset>
以上是脚本宝典为你收集整理的如何为CakePHP创建站点地图?全部内容,希望文章能够帮你解决如何为CakePHP创建站点地图?所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。