Yii Framework Forum: How To Override A Clinkpager Function For A Clistview? - Yii Framework Forum

Jump to content

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

How To Override A Clinkpager Function For A Clistview? Rate Topic: -----

#1 User is offline   chuntley 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 66
  • Joined: 23-April 10

Posted 11 January 2013 - 01:05 PM

I have a CListView that requires the links to be generated in a different way from how CLinkPager does it by default. I have narrowed it down to this function in CLinkPager (\framework\web\widgets\pagers\CLinkPager.php):

/**
 * Creates a page button.
 * You may override this method to customize the page buttons.
 * @param string $label the text label for the button
 * @param integer $page the page number
 * @param string $class the CSS class for the page button.
 * @param boolean $hidden whether this page button is visible
 * @param boolean $selected whether this page button is selected
 * @return string the generated button
 */

protected function createPageButton($label,$page,$class,$hidden,$selected)
{
	if($hidden || $selected)
	         $class.=' '.($hidden ? $this->hiddenPageCssClass : $this->selectedPageCssClass);
	return '<li class="'.$class.'">'.CHtml::link($label,$this->createPageUrl($page)).'test</li>';
}


How do I override this function for a single CListView?
0

#2 User is offline   rootbear 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 222
  • Joined: 17-June 11

Posted 11 January 2013 - 01:42 PM

do this:

copy CLinkPager.php to protected\components\XLinkPager.php and modify as:


class XLinkPager extends CLinkPager
{
//it's yours to modify, my foot step is zzz
	protected function createPageButton($label,$page,$class,$hidden,$selected)
	{
		if($hidden || $selected)
			$class.=' '.($hidden ? $this->hiddenPageCssClass : $this->selectedPageCssClass);
		return '<li class="'.$class.'">zzz'.CHtml::link($label,$this->createPageUrl($page)).'</li>';
	}
}


in your view file:

//it would be the same for listview
$this->widget('zii.widgets.grid.CGridView', array(
	'id' => 'item-grid',
	'pager' => 'XLinkPager', //<== add this


is Yii damn beauty?
I enjoy the Yii.sy coding life here.
0

#3 User is offline   chuntley 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 66
  • Joined: 23-April 10

Posted 11 January 2013 - 02:08 PM

View Postrootbear, on 11 January 2013 - 01:42 PM, said:

is Yii damn beauty?


She is mighty fine. Thank you for the clear and concise instructions, it works great!
0

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