如何在Yii中自定义寻呼机的标签? [英] How can I customize the labels for the pager in Yii?

查看:68
本文介绍了如何在Yii中自定义寻呼机的标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Yii的新手.我想实现自定义分页.我想更改寻呼机的外观.如何更改寻呼机链接的标签?

I am new to Yii. I want to implement custom pagination. I want to change the appearance of the pager. How do I change the labels of the pager's links?

我希望链接显示如下:

<<  <  1  2  3  4  >  >>

而不是默认外观,就像这样:

instead of their default appearance, which is like this:

[first] [previous]  1  2  3  4  [next] [last]

我正在使用CListView来显示数据,其设置如下:

I am using CListView to display the data, which I have set up like this:

$this->widget('zii.widgets.CListView', array(
            'dataProvider' => $categoryProjects,
            'itemView' => '_itemDetailsView',           
            'ajaxUpdate'=>false,
        ));

有人可以告诉我如何开始吗?我看过一些帖子,但无法获得正确的信息.

Can anyone please tell me how do I start with it? I've seen some posts but unable to get right information.

谢谢.

推荐答案

您需要设置 CListViewpager 属性.默认情况下,这是 CLinkPager ;您无需进行更改(此组件已满足您的需求),但是您需要对其进行配置:

You need to set the pager property of the CListView. By default, this is a CLinkPager; you don't need to change that (this component has your needs covered), but you need to configure it:

$this->widget('zii.widgets.CListView', array(
            'dataProvider' => $categoryProjects,
            'itemView'     => '_itemDetailsView',
            'ajaxUpdate'   => false,
            'pager'        => array(
                                'class'          => 'CLinkPager',
                                'firstPageLabel' => '<<',
                                'prevPageLabel'  => '<',
                                'nextPageLabel'  => '>',
                                'lastPageLabel'  => '>>',
                              ),
        ));

更新:如果要将上述自定义配置烘焙"到应用程序中的所有列表视图中,则必须创建一个新的CustomListView组件,该组件派生自CListView.因此,您需要此类:

Update: If you want to "bake in" the above custom configuration to all list views in your application, you have to create a new CustomListView component deriving from CListView. So you need this class:

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

class CustomListView extends CListView {
    public function init() {
        parent::init();

        $this->pager = array( 
                            'class'          => 'CLinkPager', 
                            'firstPageLabel' => '<<', 
                            'prevPageLabel'  => '<', 
                            'nextPageLabel'  => '>', 
                            'lastPageLabel'  => '>>', 
                       );
    }
}

添加此内容后,您只需使用CustomListView作为列表小部件即可,而不是zii.widgets.CListView.

After including this, you can simply use CustomListView as your list widget instead of zii.widgets.CListView.

这篇关于如何在Yii中自定义寻呼机的标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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