$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'columns'=>array(
'title', // display the 'title' attribute
'category.name', // display the 'name' attribute of the 'category' relation
'content:html', // display the 'content' attribute as purified HTML
array( // display 'create_time' using an expression
'name'=>'create_time',
'value'=>'date("M j, Y", $data->create_time)',
),
array( // display 'author.username' using an expression
'name'=>'authorName',
'value'=>'$data->author->username',
//HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
'htmlOptions'=>array('class'=>'$data->author->username', 'secondAttribute' => $data->author->id),
//HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
),
array( // display a column with "view", "update" and "delete" buttons
'class'=>'CButtonColumn',
),
),
));
在选项value
我可以从PHP添加变量,但对于选择htmlOptions
这是不可能的。为什么?
我如何使PHP变量的属性?的Yii - CGridView - 添加自己的属性
+1非常好的解释 – 2012-03-27 18:19:25
这和我的例子一样。这不工作 - 没有人显示。 – 2012-03-28 09:29:02
@DirkFograust:这绝对是**不像你的例子一样**。再看看。另外,请确保您使用的是最新版本的Yii。 – Jon 2012-03-28 09:38:37