Conditional Display of Controls

Hello,

Is there a better way to conditionally display controls than the format below?

<?php if(!Yii::app()->user->isGuest) {echo CHtml::encode($records['listing_id']);} ?>

I thought I might be able to do something like this, but it doesn't seem to work:

<?php echo CHtml::encode($records['listing_id'], array('visible'=>'!Yii::app()->user->isGuest'); ?>

I'm just looking for best practices with Yii.

Thanks,

R

'visible'  expects a boolean value, so should use:

<?php echo CHtml::encode($records['listing_id'], array('visible'=>!Yii::app()->user->isGuest); ?>

Personally I would go for the first option as it is faster and easier to read… i don't like Yii's 'visible' options that it has here and there.

But isn't there the problem that the browser doesn't render the control, so I can't set it visible afterwards (with javascript) ?

I think in Prado it was like this, but I’m new here and I don’t now if yii also can do that :)

greetings

phil

The 'visible'=>Yii()->user->isGuest doesn't do anything.  Html::encode doesn't seem to allow for any paramters besides the text:



encode() method


public static string encode(string $text)


$text	string	data to be encoded


{return}	string	the encoded data


That's fine, I'll just use my first example.  I was just wondering what you folks used. 

Thanks for your replies.

R