CGridView - add own attribute from PHP

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



            'title',          // display the 'title' attribute

            '',  // display the 'name' attribute of the 'category' relation

            'content:html',   // display the 'content' attribute as purified HTML

            array(            // display 'create_time' using an expression


                'value'=>'date("M j, Y", $data->create_time)',


            array(            // display 'author.username' using an expression




                  'htmlOptions'=>array('class'=>'$data->author->username', 'secondAttribute' => $data->author->id),



            array(            // display a column with "view", "update" and "delete" buttons





In option value i can add variable from PHP, but for option htmlOptions this is not possible. Why? How can i make attribute with PHP variable?

Don’t use single quote:

‘htmlOptions’=>array(‘class’=>$data->author->username, ‘secondAttribute’ => $data->author->id)

this won’t work. $data must be evaluated for every row…

Look at this wiki article:

@redguy very thanks :)