Htmloptions For Cdetailview's Items

I have a web-form based on CDetailView. After it is initally shown, its fields can be separately updated via AJAX. To do so I need every cell to have distinct id. What could help is htmlOptions in every ‘attributes’ element of the CDetailView, but I don’t see such property. Any ideas? Perhaps itemtemplate could do this, but it lacks good documentation. It’s not clear how to use it.

Looks like ‘<tr class="{class}"><th>{label}</th><td><div id=“xyz”>{value}</div></td></tr>’ does what I need. But I’m not sure if this DOM fragment will always be compatible with CDetailView.

Hi Stan

Each CDetailView attribute has a ‘cssClass’ element which allows you to specify any css class you wish to append to the <tr> tag. Each attribute also has a ‘template’ element which you can use to customise the attribute’s row. I haven’t used the ‘template’ element myself. I usually use something along the lines of:

$this->widget('zii.widgets.CDetailView', array(








            'value'=>'<span id=' . $model->id . '>' . $model->city . '</span>',

            'cssClass'=>'class-name',//appends class-name to <tr>




            'label'=>'Your label',


            'value'=>'<span id="xyz">' . $model->value . '</span>',






The Attributes section of the Detailview documentation has info on this.

I haven’t tested the code. The ‘html’ type strips out the id when I use it so I use tend to use the ‘raw’ type but only with sanitised data.