加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

如何为CakePHP创建站点地图?

发布时间:2020-12-13 18:25:55 所属栏目:PHP教程 来源:网络整理
导读:我想创建一个站点地图,但我对Sitemaps的使用知之甚少.我用Cake PHP.谷歌和指南上有很多软件,但我仍然想要问一下,为CakePHP创建站点地图的简单方法. 我在服务器上传了网站,它不依赖于localhost. 这是一个快速的例子供您玩耍并根据您的需求进行调整: 在你的控
我想创建一个站点地图,但我对Sitemaps的使用知之甚少.我用Cake PHP.谷歌和指南上有很多软件,但我仍然想要问一下,为CakePHP创建站点地图的简单方法.

我在服务器上传了网站,它不依赖于localhost.

这是一个快速的例子供您玩耍并根据您的需求进行调整:

在你的控制器中:

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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读