CLinkForum and labelExpression/urlExpression

Is it possible to use IF statements inside the labelExpressionand urlExpression properties of CLinkColumn? I’ve tried and it doesn’t seem to work…




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

    'dataProvider'=>$photoDataProvider,

    'columns'=>array(

        array(

            'class'=>'CLinkColumn',

            'header'=>'Set Active',

            'labelExpression'=>'if ($data->isActive) echo ""; else echo "myLink";',

            'urlExpression'=>'Yii::app()->createUrl("photo/activate",array("id"=>$data->ID))',

        ),

    ),

));



That’s where the alternative syntax with ? and : comes in very handy. It’s used like this:


$a = $b==5 ? 'b is 5' : 'b is not 5';



So your code will be:


'labelExpression'=> '$data->isActive ? "" : "myLink"',



BTW i’ve not used CGridView yet, but from the API docs, this should work ;)