Extend Clinkpager Example

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 ! :)

I do something extremely similar myself. Great tip! :)

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