如果不更改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";
}
這兩個答案都是正確的。如果您需要一次又一次地使用自定義列表視圖,則接受的答案會更好。這個答案適用於那些情況不好的人。 –
但是這使分頁自動? – Nisanio
無用。 熱設置分頁????? – Kiran