2014-02-16 37 views
0

我使用笨庫和我使用下面的代碼來生成XML RSS饋送文件 這是控制器的代碼: 得到在Rss.xml不想要的數據文件

class Rssfeed extends MY_Controller { 

public function Generate_rss_feed() 
{ 
    $this->load->helper('visitors'); 
    $data['visitors'] = visitors_counter($this,$this->input->ip_address()); 
    $this->load->helper('xml'); 
    $this->load->helper('text'); 
    $this->load->model('news_model'); 

    $data['feed_name'] = 'MyWebsite.com'; // your website 
    $data['encoding'] = 'utf-8'; // the encoding 
    $data['feed_url'] = base_url().'index.php/rssfeed/Generate_rss_feed'; // the url to your feed 
    $data['page_description'] = '';//some description 
    $data['page_language'] = 'ar-ar'; // the language 

    $data['posts'] = $this->news_model->get_latest_news(3); 
    header("Content-Type: application/rss+xml"); // important! 
    $data['mode']= 'rss_feed'; 
    $data['view_page']= 'rss'; 
    $this->load->view('rss', $data); 
} 
} 

並在視圖那裏分別是:

<html> 
<head> 
    <meta charset="UTF-8"> 
</head> 
<body> 

<?php 

$rss_feed = '<?xml version="1.0" encoding="' . $encoding . '"?-->' . "\n".' 
<rss version="2.0" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" > 

<channel> 
<title>'.$feed_name.'</title> 

<link>'.$feed_url.' 
<description>'. $page_description.'</description> 
<dc:language>'. $page_language.'</dc:language> 


<dc:rights>Copyright'. gmdate("Y", time()).'</dc:rights> 
<admin:generatoragent rdf:resource="http://www.codeigniter.com/">'; 
foreach($posts as $post){ 

    $rss_feed .='<item> 
     <title>'.xml_convert($post->Title).'</title> 
     <link>'.site_url('blog/posting/' . $post->ID).'</link> 
     <guid>'. site_url('blog/posting/' . $post->ID).'</guid> 
     <description>'.$post->Head_line .'</description> 
     <pubdate>'.date("F j, Y, g:i a",$post->Date).'</pubdate> 
    </item>'; 


} 
$rss_feed .= ' </admin:generatoragent></channel> 
</rss>'; 
force_download('feed.xml', $rss_feed); 
?> 
</body> 
</html> 

的問題是,當我下載的XML文件,它包含:

<html> 
<head> 
<meta charset="UTF-8"> 
</head> 
<body> 

我不知道它來自哪裏?任何幫助..

+1

不在視圖代碼的頂部你只是貼? –

+0

是的,但我強制文件中的輸出數據是變量的內容$ rss_feed –

+0

然後,只需刪除「外部代碼」,在PHP之外......所以它應該只是 fedmich

回答

1

從視圖文件中,刪除代碼中的這些行。

  • 行1 < HTML>
  • 第2行到第6行
  • 線38
  • 線39 </HTML>
+0

我這樣做,但我做不明白爲什麼? –