I have added a extra attribute (or property) in the model.
protected $rating;
public function getRating()
{
$likes = $this->getAttribute('likes');
$dislikes = $this->getAttribute('dislikes');
if ($likes != 0 && $dislikes != 0)
return $likes / ($likes + $dislikes) * 10;
}
…and my controller:
public function actionIndex()
{
$dataProvider=new CActiveDataProvider('Game');
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
View:
<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
'enablePagination'=>true,
'enableSorting'=>true,
'sortableAttributes'=>array(
'name',
'releaseyear',
'developer',
'rating',
),
'template'=>'{sorter}{items}{summary}{pager}'
)); ?>
What I want to accomplish is to sort on Rating, but as you can see on the picture provided, the "link" is not clickable. Any suggestions?