How can I customize the labels for the pager in Yii?

后端 未结 2 398
眼角桃花
眼角桃花 2021-01-05 08:49

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 li

相关标签:
2条回答
  • 2021-01-05 09:40

    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'  => '>>',
                                  ),
            ));
    

    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'  => '>>', 
                           );
        }
    }
    

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

    0 讨论(0)
  • 2021-01-05 09:46

    You can refer the link:

    Yii2: How to setup pagination style and other labels

    Here you will get most of the options to set up for the custom pagination labels

    0 讨论(0)
提交回复
热议问题