Display Uploaded File Only If It Exisits

Hi there,

I have a file upload field to upload an image, in the view I want to display the uploaded image which I have achieved like this in view.php:


array( 

			'name'=>'main_image',

			'label'=>'Main Image',

			'type'=>'raw',

			'value'=>html_entity_decode(CHtml::image(Yii::app()->baseUrl . '/mainImages/'.$model->main_image,'Main Image (this is the alt tag)',array('width'=>200))),

		),

But I only want it to display if the image has been uploaded. So I guess I need to check if $model->main_image is empty or not. What’s the best way to do this?

Thanks in advance!

Put an expression in the visible property of an attribute definition.

Thanks for that. I’ve also managed to do it this way it this way:


$model->main_image!=null ? array( 

			'name'=>'main_image',

			'label'=>'Main Image',

			'type'=>'raw',

			'value'=>html_entity_decode(CHtml::image(Yii::app()->baseUrl . '/propertyImages/'.$model->main_image,'Main Image (this is the alt tag)',array('width'=>200))),

		) : array( 

			'name'=>'main_image',

			'label'=>'Main Image',

			'value'=>'No main image selected.'),