Enable or disable two icons I need two icons:


If the email is verified, show an icon without a hyperlink and set an "activated" CSS class for green style and checked.
If the email is not verified, the icon is linked to the verify page, and the default is a gray color style.


Which of these solutions is better and standard?

Solution #1:

&lt;a href="&lt;?php echo ($modelStatic-&gt;isVerifiedEmail) ? 'javascript:void(0)' :
    Yii::app()-&gt;createUrl('/user/reActivate'); ?&gt;"
   class="item&lt;?php if($modelStatic-&gt;isVerifiedEmail) echo ' activated'; ?&gt;"&gt;
    &lt;div class="confirm-icon"&gt;
        &lt;i class="fa fa-envelope-o"&gt;&lt;/i&gt;
    &lt;/div&gt;
    &lt;div class="text"&gt;
        &lt;?php echo Yii::t('app', 'Verify Email'); ?&gt;
    &lt;/div&gt;
&lt;/a&gt;
&lt;style&gt;
.activated {
    cursor: default;
}
&lt;/style&gt;


Solution #2:

if($modelStatic-&gt;isVerifiedEmail) : ?&gt;
    &lt;div class="item activated"&gt;
        &lt;div class="confirm-icon"&gt;
            &lt;i class="fa fa-envelope-o"&gt;&lt;/i&gt;
        &lt;/div&gt;
        &lt;div class="text"&gt;
            &lt;?php echo Yii::t('app', 'Verify Email'); ?&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;?php else: ?&gt;
    &lt;a href="&lt;?php echo Yii::app()-&gt;createUrl('/user/reActivate'); ?&gt;"
       class="item"&gt;
        &lt;div class="confirm-icon"&gt;
            &lt;i class="fa fa-envelope-o"&gt;&lt;/i&gt;
        &lt;/div&gt;
        &lt;div class="text"&gt;
            &lt;?php echo Yii::t('app', 'Verify Email'); ?&gt;
        &lt;/div&gt;
    &lt;/a&gt;
&lt;?php endif; ?&gt;


Solution #3:

&lt;?php if($modelStatic-&gt;isVerifiedEmail) : ?&gt;
    &lt;div class="item activated"&gt;
&lt;?php else: ?&gt;
    &lt;a href="&lt;?php echo Yii::app()-&gt;createUrl('/user/reActivate'); ?&gt;" class="item"&gt;
&lt;?php endif; ?&gt;
        &lt;div class="confirm-icon"&gt;
            &lt;i class="fa fa-envelope-o"&gt;&lt;/i&gt;
        &lt;/div&gt;
        &lt;div class="text"&gt;
            &lt;?php echo Yii::t('app', 'Verify Email'); ?&gt;
        &lt;/div&gt;
&lt;?php if($modelStatic-&gt;isVerifiedEmail) : ?&gt;
    &lt;/div&gt;
&lt;?php else: ?&gt;
    &lt;/a&gt;
&lt;?php endif; ?&gt;
I don't know about standard, so I'll just say what I see.

I found that the second is cleanest of all three and easiest to read.  The logic flow is very simple, with just one simple if/else.  However, it is not DRY, with all the problems that that entails.

the first and third are both a bit more complex.
the third also has the same if block defined twice (once at the beginning and once at the end), which makes it also not DRY

regarding the first, I personally don't like the idea of creating an a tag that gets javascript:void(0). It seems that it will just add clutter to the rendered page.

The other problem (with all three) is that you have your logic mixed in to the html. I would recommend something like as follows:

&lt;?php 
    //first define all the variable items
if($modelStatic-&gt;isVerifiedEmail) : 
    $startTag = '&lt;div class="item activated"&gt;';
    $endTag = '&lt;/div&gt;';
else:
    $startTag = '&lt;a href="&lt;?php echo Yii::app()-&gt;createUrl('/user/reActivate'); class="item"&gt;'
    $endTag = '&lt;/a&gt;';
endif; ?&gt;


     &lt;?=$startTag?&gt;
        &lt;div class="confirm-icon"&gt;
            &lt;i class="fa fa-envelope-o"&gt;&lt;/i&gt;
        &lt;/div&gt;
        &lt;div class="text"&gt;
            &lt;?php echo Yii::t('app', 'Verify Email'); ?&gt;
        &lt;/div&gt;
     &lt;?=$endTag?&gt;