yii - 如何扩展 CListView 以删除额外的 yii 添加标记?

标签 yii

重点是从 CListView 渲染中移除这两个 div:

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

我一直在看这里:

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

但我在那里没有发现与这两个 div 相关的内容。

谁能分享一下,我们应该扩展什么才能实现这一点?

这是所需输出的更新:

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

最佳答案

您最好从 CListView 本身扩展,但为 run() 编写新的实现 method in CBaseListViewrenderItems() 的新实现 method in CListView ,例如:

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);
    }
}

编辑:

请注意,某些默认的 clistview 功能仅适用于此,因为 jquery.yiilistview.js没有标识此 ListView 的 ID 将无法工作。

编辑:

根据您更新的问题,您可以这样做,然后:

<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>

关于yii - 如何扩展 CListView 以删除额外的 yii 添加标记?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12298209/

相关文章:

php - 在 PHP、Yii 和 Swift 的帮助下从字符串发送附件

php - 在 PHP 中执行的 MySQL 查询导致非常大的 httpd 线程

css - 如何在不删除标题消息的情况下将类添加到 errorsummay

Yii-外部JS文件包括,registerScriptFile和发布

yii - YII 中的 setAttribute() 函数不起作用

php - Yii2 ActiveRecord Stat 关系

php - 根据下拉列表中的更改更改 GridView 中的数据

php - 使用 yii sleep 前输出

php - Yiibooster TbButton 网址链接无效

php - 尝试登录时 Yii2 中的错误请求 (#400)