Changing the class name generated by ClistView Yii

728 Views Asked by At

Just a simple question, is it possible to change the classname generated by ClistView ?

by default, it generates

<div class="post">

for all the list.

I'd like to have

<div class=post1>

<div class=post2>

...

2

There are 2 best solutions below

0
On

You can customize CListView styles with bellow parameters:

$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$YOUR_DATA_PROVIDET,
'itemView'=>'...',
'sortableAttributes'=>array(),
'cssFile'=>' YOU CAN ASSIGN A CSS FILE TO YOUR CLISTVIEW',
'itemsCssClass'=>'SOME CLASS',
'pagerCssClass'=>'SOME CLASS',
'sorterCssClass'=>'SOME CLASS',
'summaryCssClass'=>'SOME CLASS',
));

for more information you can check CListView's Official document in the following link:

CListView

UPDATE:

If you want to change other names, you must edit the source of yii's CGridView. But changing the style of it could be more easier.

0
On

If you want a different, incrementing class on each looped list item, change your itemView partial like this:

using the ID of each model:

<div class="post<?php print $data->id; ?>"> 
<?php

print_r($data->attributes); // Or whatever

?>
</div>

using the 'index' of the current iteration:

<div class="post<?php print $index; ?>"> 
<?php

print_r($data->attributes); // Or whatever

?>
</div>

More info available here