Yii Framework Forum: CLinkForum and labelExpression/urlExpression - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CLinkForum and labelExpression/urlExpression Rate Topic: -----

#1 User is offline   edwaa 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 17-May 09
  • Location:Seattle, WA

Posted 28 February 2010 - 10:53 PM

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))',
        ),
    ),
));

0

#2 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,016
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 01 March 2010 - 03:46 AM

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 ;)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users