• About Me




    Lily@Melbourne, Australia

    Login

  • Follow 静水深流 || Still waters run deep on WordPress.com
  • Archives

CakePHP sitemap

链接:http://bakery.cakephp.org/articles/masterkeedu/2008/08/26/automatically-generate-dynamic-sitemaps

Sitemap虽然不是必须,但为了提高网站的可见度,确是必不可少地。如果根据以上例子来做的话,那么所有需要可见的Model都要一个字一个字地加进去,很麻烦是吧,以下是我的简化版本

1,创建 /app/controllers/Sitemapscontroller.php

class SitemapsController extends AppController {

var $name = ‘Sitemaps’;
var $uses = null;

/**

* index method
*
* @return void
*/
public function index() {
$this->layout = ‘simple’; //使用简化版的框架
}
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow(‘index’); //允许所有人都浏览这个页面
}
}

2,  Get sitemap
http://www.xml-sitemaps.com 这个网站会自动生成你网站的sitemap, 下载sitemap.xml到硬盘。

3, 创建 /app/views/Sitemaps/index.ctp

内容就是在第2步下载的sitemap.xml

4, 创建 /app/views/Layout/simple.ctp
这个sitemap 可不需要什么花里胡哨的logo, image,menu, header, footer之类的
code很简单,一句话:

<?php echo $content_for_layout; ?>

5, /app/config/routes.php 加路由

例子上还需要加这一行, 但报错 Router::parseExtensions(‘xml’);

Router::connect(‘/sitemap.xml’, array(‘controller’ => ‘sitemaps’, ‘action’ => ‘index’));

6,测试
输入地址 yourwebsite/sitemap.xml

7, 告诉Google

Google Webmaster account, 搞定:)

Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: