Codeigniter站点地图不工作


codeigniter sitemap not working

我正在codeignite中创建一个站点地图。但我面临一些错误与站点地图。谁能告诉我什么是错误?

控制器

: -

 public function sitemap()
 {
     header("Content-Type: text/xml;charset=iso-8859-1");
     $this->load->view("sitemap");        
 }

视图:-

<?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>    
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">    
   <url>    
      <loc>http://www.example.com/</loc>    
      <lastmod>2005-01-01</lastmod>    
      <changefreq>monthly</changefreq>    
      <priority>0.8</priority>    
   </url>    
</urlset>

错误:-

XML解析错误:XML或文本声明不在实体的开始地点:http://localhost/project/index.php/sitemap.xml第2行第1列:^

controller

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {

public function index()
{
    $this->load->view('welcome_message');
}
public function sitemap()
{
    header("Content-Type: text/xml;charset=iso-8859-1");
    $this->load->view("sitemap");        
}
}
视图

<?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>    
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">    
  <url>    
   <loc>http://www.example.com/</loc>    
   <lastmod>2005-01-01</lastmod>    
   <changefreq>monthly</changefreq>    
   <priority>0.8</priority>    
 </url>    
</urlset>

页面加载正常…当我将其保存为sitemap.xml而不是sitemap.php

时,我只能复制错误消息。

首先:

删除此

<?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>    

和在/view/sitemap.php页面

顶部添加以下行
<?= '<?xml version="1.0" encoding="UTF-8" ?>' ?>

最后,将站点地图页面调用为.xml在/config/routes.php

中添加以下行
$route['controller_name/sitemap'.xml'] = "controller_name/sitemap";