【发布时间】:2015-04-04 23:49:35
【问题描述】:
我正在使用这个 RSS extension 并按照文档中的示例进行操作。
在我看来
Yii::import('ext.feed.*');
// RSS 2.0 is the default type
$feed = new EFeed();
$feed->title= 'Testing RSS 2.0 EFeed class';
$feed->description = 'This is test of creating a RSS 2.0 Feed';
$feed->setImage('Testing RSS 2.0 EFeed class','http://www.ramirezcobos.com/rss',
'http://www.yiiframework.com/forum/uploads/profile/photo-7106.jpg');
$feed->addChannelTag('language', 'en-us');
$feed->addChannelTag('pubDate', date(DATE_RSS, time()));
$feed->addChannelTag('link', 'http://www.ramirezcobos.com/rss' );
// * self reference
$feed->addChannelTag('atom:link','http://www.ramirezcobos.com/rss/');
$item = $feed->createNewItem();
$item->title = "first Feed";
$item->link = "http://www.yahoo.com";
$item->date = time();
$item->description = 'This is test of adding CDATA Encoded description <b>EFeed Extension</b>';
// this is just a test!!
$item->setEncloser('http://www.tester.com', '1283629', 'audio/mpeg');
$item->addTag('author', 'thisisnot@myemail.com (Antonio Ramirez)');
$item->addTag('guid', 'http://www.ramirezcobos.com/',array('isPermaLink'=>'true'));
$feed->addItem($item);
$feed->generateFeed();
Yii::app()->end();
在我的控制器中
public function actionFeed()
{
$this->renderPartial('feed');
}
在 Firefox 中我收到此错误
XML Parsing Error: XML or text declaration not at start of entity
Location: http://localhost/dev/frontend/www/abc/bla/feed/
Line Number 1, Column 2: <?xml version="1.0" encoding="UTF-8"?>
-^
在 chrome 中
This page contains the following errors:
error on line 1 at column 6: XML declaration allowed only at the start of the document
Below is a rendering of the page up to the first error.
扩展中有这个功能
public function generateFeed(){
header("Content-type: text/xml");
$this->renderHead();
$this->renderChannels();
$this->renderItems();
$this->renderBottom();
}
当我注释掉header("Content-type: text/xml"); 时没有错误,但页面显示为 html 并且全部在 1 行中。但是当您查看源代码时,标签都已到位。
第一两行是这样的
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
知道我做错了什么吗?
【问题讨论】:
标签: php xml yii rss yii-extensions