生成站点地图无法正常工作

时间:2015-05-01 09:05:41

标签: codeigniter sitemap

我需要生成站点地图并在我的视图中显示。但是我收到此错误: -

error on line 1 at column 2: StartTag: invalid element name

控制器: -

class Sitemap extends CI_Controller {

public function index()
{
    $this->load->view('sitemap/sitemap.html');
}
}

查看: -

<?php header('Content-type: text/xml'); ?>
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>http://www.domain.com /</loc>
<lastmod>2008-01-01</lastmod>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
</url>
<url>
<loc>http://www.domain.com/catalog?item=vacation_hawaii</loc>
<changefreq>weekly</changefreq>
</url>
</urlset> 

1 个答案:

答案 0 :(得分:1)

试试这个Sitemap generation with Codeigniter

contoroller:

Class Sitemap extends CI_Controller {

    function index()
    {

        $data = "";//select urls from DB to Array
        header("Content-Type: text/xml;charset=iso-8859-1");
        $this->load->view("sitemap",$data);
    }
}

视图:

<?= '<?xml version="1.0" encoding="UTF-8" ?>' ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    <url>
        <loc>http://www.domain.com /</loc>
        <lastmod>2008-01-01</lastmod>
        <changefreq>weekly</changefreq>
        <priority>0.8</priority>
    </url>
    <url>
        <loc>http://www.domain.com/catalog?item=vacation_hawaii</loc>
        <changefreq>weekly</changefreq>
    </url>
</urlset>

添加到config / routes.php的行:

$route['seo/sitemap\.xml'] = "seo/sitemap";

=&GT; roev的答案