How to display Yii's CLinkPager first and last

2019-09-17 21:36发布

问题:

My page number is like:

Page:1 2 3 4 5 last

But I want to change it like:

<< first | < previous | 1 | ... | 5 | next > | last >>

How to change this?

My code is:

<?php
$this->widget('CLinkPager', array(
    'currentPage' => $pages->getCurrentPage(),
    'itemCount' => $item_count,
    'pageSize' => $page_size,
    //'linkHash'=>'ls',
    'maxButtonCount' => 5,
    'firstPageLabel' => '',
    'prevPageLabel' => '',
    'nextPageLabel' => '',
    'lastPageLabel' => 'last',
    'header' => '<p>Page:</p>',
    /*'pager'=>array(
    'class'=>'MyLinkPager',
    'linkHash'=>'test'
    ),*/

    'htmlOptions' => array(
        'class' => 'pages'
    )
)); ?> 

回答1:

Try this

<?php
   $this->widget('CLinkPager', array(
      'currentPage' => $pages->getCurrentPage(),
      'itemCount' => $item_count,
      'pageSize' => $page_size,
      //'linkHash'=>'ls',
     'maxButtonCount' => 5,
     'selectedPageCssClass'=>'active',
     'hiddenPageCssClass'=>'disabled',
     'firstPageCssClass'=>'previous',
     'firstPageLabel' => '<< first | ',
     'prevPageLabel' => 'previous |',
     'nextPageLabel' => ' | next',
     'lastPageLabel' => ' | last >>',
     'header' => '<p>Page:</p>',
     /*'pager'=>array(
       'class'=>'MyLinkPager',
'      linkHash'=>'test'
     ),*/

  'htmlOptions' => array(
    'class' => 'pages'
  )
)); ?> 


回答2:

In this case you need to set a page labels. You can use this instead of yout current definition:

'firstPageLabel' => '&laquo;&laquo; first',
'prevPageLabel' => '&laquo; previus',
'nextPageLabel'=>'next &raquo;',
'lastPageLabel'=>'last &raquo;&raquo;',
'maxButtonCount' => 5

To style a vertical separator you can use a css:

'cssFile' => Yii::app()->request->baseUrl . '/css/your_pager_css.css',

Place new css file to css dir and define a needed styles of a pager.

Some ideas: http://www.yiiplayground.com/index.php?r=UiModule/pagination/basicPager

How to customize Yii CGridView Pager?



标签: php yii