我试图用CListView生成RSS页面,但我在结果中得到了额外生成的html:
<div id="yw0" class="list-view">
<div class="items">
和
<div class="keys" style="display:none" title="/index.php/rss"><span>2383</span><span>4743</span><span>1421</span></div>
我该如何删除它?
答案 0 :(得分:12)
INSTEAD使用CListView,只需使用它的内容:
$data = $dataProvider->getData();
foreach($data as $i => $item)
Yii::app()->controller->renderPartial('your_item_view',
array('index' => $i, 'data' => $item, 'widget' => $this));
就是这样。
答案 1 :(得分:1)
如果不更改CListView类(yii v.1.1.8),则无法执行此操作。
CListView扩展了CBaseListView http://code.google.com/p/yii/source/browse/tags/1.1.8/framework/zii/widgets/CBaseListView.php
/**
* Renders the view.
* This is the main entry of the whole view rendering.
* Child classes should mainly override {@link renderContent} method.
*/
public function run()
{
$this->registerClientScript();
echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n";
$this->renderContent();
$this->renderKeys();
echo CHtml::closeTag($this->tagName);
}
/**
* Renders the key values of the data in a hidden tag.
*/
public function renderKeys()
{
echo CHtml::openTag('div',array(
'class'=>'keys',
'style'=>'display:none',
'title'=>Yii::app()->getRequest()->getUrl(),
));
foreach($this->dataProvider->getKeys() as $key)
echo "<span>".CHtml::encode($key)."</span>";
echo "</div>\n";
}
答案 2 :(得分:0)
在Yii网站上有关于generating Feeds的非常好的wiki教程。 CListView旨在显示项目的html列表,而不是任何类型的Feed。