Yii Framework Forum: CListView sort links "nofollow" - Yii Framework Forum

Jump to content

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

CListView sort links "nofollow" Rate Topic: -----

#1 User is offline   petko 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 34
  • Joined: 24-February 10
  • Location:Bulgaria

Posted 09 September 2010 - 07:02 AM

I want to add "rel"="nofollow" to sort links to my CListView. Unfortunately, I can't find how to access the individual sorting attributes for CListView.

Can you point me to a solution?
0

#2 User is offline   Jaz Manister 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 109
  • Joined: 27-October 09
  • Location:Rural Western New York, USA

Posted 09 September 2010 - 08:53 AM

View Postpetko, on 09 September 2010 - 07:02 AM, said:

I want to add "rel"="nofollow" to sort links to my CListView. Unfortunately, I can't find how to access the individual sorting attributes for CListView.

Can you point me to a solution?


In the _view.php file that goes with your CListView you should be doing some kind of CHtml::link() call. Take a look at the third parameter section (api) of this. You can add this under htmlOptions.

  //api definition
  public static string link(string $text, mixed $url='#', array $htmlOptions=array ( ))

  //example
  CHtml::link('mylinktext', 'myurl', array('rel'=>'nofollow'));

0

#3 User is offline   petko 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 34
  • Joined: 24-February 10
  • Location:Bulgaria

Posted 09 September 2010 - 01:06 PM

Thanks. I know how to do this, but the problem is how to access the htmlOptions parameter for the sort links of CListView in order to add it there?
0

#4 User is offline   litcor 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 36
  • Joined: 22-November 10
  • Location:Chengdu

Posted 27 April 2011 - 10:32 PM

View Postpetko, on 09 September 2010 - 01:06 PM, said:

Thanks. I know how to do this, but the problem is how to access the htmlOptions parameter for the sort links of CListView in order to add it there?


Yes, that is the most important thing(for SEO)~ I want to solve this problem, too. Who can help?
创意人,创意-连接你我!
感谢Yii框架让我个门外汉走上互联网创业之路!

ccihr, Cultural & Creative Industry Recruitment Platform
0

#5 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,017
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 28 April 2011 - 02:22 AM

I see no other way than to extend CListView and override renderSorter(). It's a pretty easy task though:

Yii::import('zii.widgets.CListView');
class MyListView extends CListView
{
    public function renderSorter()
    {
        // Copy original code here and adapt as needed. Try to be generic, 
        // to enable reuse of your class, e.g. use a new property for sort link htmlOptions
    }
}

0

#6 User is offline   chux 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 83
  • Joined: 16-September 10

Posted 06 May 2011 - 01:17 PM

Maybe this helps someone:
Yii::import('zii.widgets.CListView');

class MyListView extends CListView{


	public $customSorterAttributes = array(
		'rel' => 'nofollow',
	);
	
	public function renderSorter(){
		if($this->dataProvider->getItemCount()<=0 || !$this->enableSorting || empty($this->sortableAttributes))
			return;
		echo CHtml::openTag('div',array('class'=>$this->sorterCssClass))."\n";
		echo $this->sorterHeader===null ? Yii::t('zii','Sort by: ') : $this->sorterHeader;
		echo "<ul>\n";
		$sort=$this->dataProvider->getSort();
		foreach($this->sortableAttributes as $name=>$label)
		{
			echo "<li>";
			if(is_integer($name))
				echo $sort->link($label, null, $this->customSorterAttributes);
			else
				echo $sort->link($name,$label, $this->customSorterAttributes);
			echo "</li>\n";
		}
		echo "</ul>";
		echo $this->sorterFooter;
		echo CHtml::closeTag('div');
		}

}


and in your view

$this->widget('myListView', array(.......

Give a read to my blog.
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