If/else statement in CHtml::image ?

I am echoing a link then I am echoing the user’s name that will complete the link.

Example:




echo CHtml::link(CHtml::image('/images/profile.png'), "$members->memberURL $members->memberName", array('target'=>'_blank'));



This works perfectly. However, what if no "memberName" is entered when I create the ID.

Can I enter an "if" statement into this and NOT display the link if no "memberName" is entered?

like




$members = memberName; 

if ( $memberName == $memberName ) 

{ 	

echo "Hi, my URL is $members->memberURL / $member->Name"; 

} 

else { 	echo "   ";

 }




Just a rough example. Can I put this in an array and make it like so?

I have found an easier way to do this by simply adding the URL when the name is added. If no name is added in the form, no URL is added therefore there is no URL to display.

Now I just need to figure out how to not display the image.

Ok found out how:




$members->memberURL= $members->memberURL;

 if ($members->memberURL == null ) {

		echo ' '; }

      	else {

	echo CHtml::link(CHtml::image('/images/profile.png'), "$members->memberURL", array('target'=>'_blank'));

}




Thank you.

Or an even cleaner solution:




if ($members->memberURL != null ) {

    echo CHtml::link(CHtml::image('/images/profile.png'), "$members->memberURL", array('target'=>'_blank'));

}



Thank you.

Just to answer the initial question: Yes, you can add an if condition inside CHtml::image()! Here’s an example showing 3 conditions as for src, alt, and title attributes of the img tag:




array(

	'header'=>'Status',

	'name'=>'active',

	'type'=>'raw',

	'filter'=>User::model()->activeOptions,

	'value'=>'CHtml::link(

		CHtml::image(url("/images/icons/square_".($data->active?\'green\':\'red\').".png"), 

		"Status: ".($data->active?\'active\':\'inactive\'), 

		array("title"=>"Status: ".($data->active?\'active\':\'inactive\')." => click to switch!")), 

		"#"

	)',

	'headerHtmlOptions'=>array('style'=>'width:30px;'),

	'htmlOptions'=>array('style'=>'padding-left:5px; padding-right:5px; text-align:center;'),

),



Hope it helps someone someday…