How to extend CListView in order to remove extra yii added markup?

霸气de小男生 提交于 2019-12-19 03:57:00

问题


The point is to remove from CListView render, those two divs:

<div id="yw0" class="list-view">
<div class="items">

I've been looking here:

https://github.com/yiisoft/yii/blob/master/framework/zii/widgets/CBaseListView.php#L123

But I found nothing related with those two divs there.

Can anyone please share, what should we extend in order for make this a reality ?

Here's an update of the desired output:

<div>
  <article class="itemthing">
    list data
  </article>
  <article class="itemthing">
    list data
  </article>
  <article class="itemthing">
    list data
  </article>
</div>

回答1:


You'd be better off extending from CListView itself, but write new implementations for run() method in CBaseListView and a new implementation for the renderItems() method in CListView, for example:

Yii::import('zii.widgets.CListView');
class MListView extends CListView{
    public function run(){
            $this->registerClientScript();
            // this line renders the first div
            //echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n"; 

            $this->renderContent();
            $this->renderKeys();

            //echo CHtml::closeTag($this->tagName);
    }

    public function renderItems(){
            //this line renders the second div
            //echo CHtml::openTag($this->itemsTagName,array('class'=>$this->itemsCssClass))."\n"; 
            // copy original code from the function
            //echo CHtml::closeTag($this->itemsTagName);
    }
}

Edit:

Be aware that some of the default clistview functionality will not work with only this much, because the jquery.yiilistview.js will not work without an id, that identifies this listview.

Edit:

From your updated question, you can do this, then:

<div id="some-id">
<?php
    $this->widget('ext.extendedwidgets.MListView',array(
        'id'=>'some-id', // same id you specified in the div
        //... rest of it
        'template' => '{items}', // as seen in the chat below
    ));
</div>


来源:https://stackoverflow.com/questions/12298209/how-to-extend-clistview-in-order-to-remove-extra-yii-added-markup

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!