如何在 Yii 中自定义寻呼机的标签?

2022-01-04 00:00:00 php pagination yii paging

我是 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?

我希望链接看起来像这样:

I want the links to appear like so:

<<  <  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 组件,该组件来自 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.

相关文章