Display ClistView differently depending on attribute values.

Hi all, Im writing up a private messaging module, now for my inbox im using CActiveDataProvider and passing it to a ClistView in my view. Now I want to make every message that is not read display different, like Become bold or something.

Now how do i do this using a ClistView, assuming i have an "is_read" attribute in my model which is a boolean value. Im thinking an if statement somewehere, but where and how?

You can specify the template of items in clistview. Using that, one solution i can think of is using different templates based on the view status of the row…


<?php $this->widget('zii.widgets.CListView', array(

        'dataProvider'=>$dataProvider,

        'itemView'=>'_view',

        'template'=>'<div class=listitem_'.$data->is_read.'>{items}</div>',

        'enableSorting' => true,

        'sortableAttributes'=>array(

            'name'=>'By name',

        ),

)); ?>

now assuming is_read returns 1 for read and 0 for unread, you can have a css rule -


listitem_1

{

     font-weight:bold;

     font-color: red;

}

view used to render every post is a php script and every php construction (if, for, foreach) will work there as expected…

Thanks will give this a try, seems like a good solution.