【问题标题】:codeigniter sitemap not workingcodeigniter 站点地图不起作用
【发布时间】:2016-09-21 12:43:51
【问题描述】:

我正在使用 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 列: ^

【问题讨论】:

  • 将文件名从sitemap.xml改为sitemap.php
  • 我在这个框架的codeigniter中开发站点地图只接受.php所以我已经创建了sitemap.php

标签: php xml codeigniter syntax-error sitemap


【解决方案1】:

控制器

<?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 时,我只能复制错误消息

【讨论】:

  • 发表评论而不是答案!
  • 编辑答案以显示控制器并查看我用来显示您想要的内容...
【解决方案2】:

首先:

删除这个

<?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"; 

希望这会对你有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-27
    • 1970-01-01
    • 2012-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多