Yii CGridView为数据值分配类


Yii CGridView assign class on data value

我比Yii大,正在尝试制作一个应用程序。

在我看来,我正在使用

zii.widgets.grid.CGridView

我有一列显示结果如下

array(
 'name'  => 'name',
  'value' => 'CHtml::link("<span class='"label label-success'">".$data->getStatus()."</span> ".$data->name."<br> View Status <br> Copy Draft)',
'type'  => 'raw',
 ),

这里我有<span class=,我想根据$data->getStatus()的数据更改SPANclass,就像如果Status is Draft,我想将类分配为Label Warning,当Status is Sent时,我想分配类label label-success

我该怎么做?

感谢

您可以在CActiveRecord 中添加函数

class YourClasseModel extends CActiveRecord 
{

    public function renderYourValue($data,$row)
    {
        if ($data->getStatus == 'Sent')  {
            return CHtml::link("<span class='"label label-success'">".$data->getStatus()."</span> ".$data->name."<br> View Status <br> Copy Draft");
        }
        if ($data->getStatus == 'Draft')
    }
.......

 'value'=>array($model,'renderYourValue'), 

调用列中的函数

array(
    'name'  => 'name',
    'value' =>     'value'=>array($model,'renderYourValue'), 
    'type'  => 'raw',
 ),