CListView sort links "nofollow"

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'));



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?

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

    }

}

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(.......