Yii - 修改 CListView 生成的 html [英] Yii - Modifing html generated by CListView

查看:14
本文介绍了Yii - 修改 CListView 生成的 html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 ClistView 来显示数据提供者的内容.

I'm using ClistView to display the content of a dataprovider.

ClistView 应该调用一个局部视图,它将为每个模型循环.

ClistView is supposed to call a partial view, that will loop for each model.

我想在第一个模型之前显示一些东西(即标签),在分页的最后一个模型之后显示一些东西(即 a ).

I would like to display something (i.e. a tag) before the first model and something (i.e. a ) after the last model of the pagination.

假设我有一个视图 (index.php):

Assume that I have a view (index.php):

$this->widget('zii.widgets.CListView', array(
                    'dataProvider'=>$localDataProvider,
                    'itemView'=>'_view',   // refers to the partial view named '_post'
                    'summaryText'=>'Sono visualizzati i record da {start} a {end} su un totale di {count} libri',
                    'pager' => Array(
                    'header' => 'Vai alla pagina',
                    'prevPageLabel' => 'Indietro',
                    'nextPageLabel' => 'Avanti',
                    ),
                    ));

在 _view.php 中,我只有表格的单元格.

In _view.php I have just the cells of a table.

如果我将 html 放在小部件之前以呈现表格标题,而在 html 之后以呈现表格页脚,我会在 div 中获得寻呼机的 html.

If I put before the widget the html to render the table header and just after the html to render the table footer I obtain that inside the div there is the html of the pager.

如何在 _view.php 中直接移动页眉和页脚?

How I can shift the header and the footer directly in _view.php?

谢谢

推荐答案

有了这个类扩展:

Yii::import('zii.widgets.CListView');

class PlainCListView extends CListView

{

public $preItemsTag = '';
public $postItemsTag = '';

public function renderItems()
{
    echo $this->preItemsTag."\n";
    $data=$this->dataProvider->getData();
    if(($n=count($data))>0)
    {
        $owner=$this->getOwner();
        $render=$owner instanceof CController ? 'renderPartial' : 'render';
        $j=0;
        foreach($data as $i=>$item)
        {
            $data=$this->viewData;
            $data['index']=$i;
            $data['data']=$item;
            $data['widget']=$this;
            $owner->$render($this->itemView,$data);
            if($j++ < $n-1)
                echo $this->separator;
        }
    }
    else
        $this->renderEmptyText();
    echo $this->postItemsTag."\n";

}


 }

我可以覆盖类的基本版本的行

I's possible to override the lines of the base version of the class

echo CHtml::openTag($this->itemsTagName,array('class'=>$this->itemsCssClass))."\n";

echo CHtml::closeTag($this->itemsTagName);

使用带有代码的解决方案:

With this solution with code:

$pre_html = '<table><thead><th>Codice Account</th><th>Nome</th></thead><tbody>';
$post_html = '</tbody></table>';

$this->widget('zii.widgets.PlainCListView', array(
                    'dataProvider'=>$dataProvider,
                    'itemView'=>'_view', 
                    'preItemsTag'=>$pre_html,
                    'postItemsTag'=>$post_html,
                    'summaryText'=>'Sono visualizzati i record da {start} a {end} su un totale di {count} libri',
                    'pager' => Array(
                    'header' => 'Vai alla pagina',
                    'prevPageLabel' => 'Indietro',
                    'nextPageLabel' => 'Avanti',
                        ),
                    'sortableAttributes'=>array('titolo'),
                    'enableSorting'=>0,



));

可以得到我需要的输出.

It's possible to get in the output what I need.

这篇关于Yii - 修改 CListView 生成的 html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆