2011-10-24 23 views
2

我試着去生成CListView中RSS頁面,但我在我的結果得到了額外生成的html:Yii的CListView中:如何禁用所有額外的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> 

我怎樣才能將其刪除?

回答

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"; 
    } 
12

實際上它很簡單,只有幾行代碼。

而不是使用CListView中,只是使用它的膽量:

$data = $dataProvider->getData(); 
foreach($data as $i => $item) 
    Yii::app()->controller->renderPartial('your_item_view', 
    array('index' => $i, 'data' => $item, 'widget' => $this)); 

就是這樣。

+0

這兩個答案都是正確的。如果您需要一次又一次地使用自定義列表視圖,則接受的答案會更好。這個答案適用於那些情況不好的人。 –

+0

但是這使分頁自動? – Nisanio

+1

無用。 熱設置分頁????? – Kiran

0

Yii網站上有關於generating Feeds的很好的wiki教程。 CListView旨在顯示項目的HTML列表,而不是任何種類的Feed。