Yii Framework Forum: Extend Clinkpager Example - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Extend Clinkpager Example

#1 User is offline   riyazMuhammed 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 13-September 12
  • Location:Bangalore

Posted 18 March 2013 - 05:43 AM

Hi I wanted to remove the previous link from the first page and next link from the last page.

So I did the following,

Step 1 :

Create a php file under the extensions directory. Something like this


Now write a class inside this file which extends the CLinkPager that comes default with your app.

class myPager extends CLinkPager{
    protected function createPageButtons()
			return array();

		$currentPage=$this->getCurrentPage(false); // currentPage is calculated in getPageRange()

		// first page

		// prev page
                //Riyaz: if we are in 1st page, lets not show the previous link

		// internal pages

		// next page
                //Riyaz: if we are already in last page, lets not show the next link
                if($currentPage+1 < $pageCount)

		// last page

		return $buttons;

Look below the next and previous link creation comments.
The Previous link, I have removed it when we are in first page.
Similarly Next link, I have removed it when we are already in the last page.

Step 2:
Combine your pager with CGridview or CListView as follows

$this->widget('zii.widgets.grid.CGridView', array(

Note the last line, I have called my newly created class as the pager.

I wanted to share this tip because there are many people who are still using CSS / JAVASCRIPT to hide this or so. So thought this would be the best solution.

Cheers ! :)

#2 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 3,710
  • Joined: 10-October 10
  • Location:Denmark

Posted 18 March 2013 - 06:13 AM

I do something extremely similar myself. Great tip! :)
"Less noise - more signal"

#3 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 18 March 2013 - 11:23 AM

Dear Riaz

I really appreciate you for sharing the tip with us.

In this regard, I want to share something with you.

By registering the following bit of css in admin.php, we can achieve the same functionality.

Yii::app()->clientScript->registerCss('last_first_hider','ul.yiiPager .hidden a


Share this topic:

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users