2013-10-13 52 views
-5

下面的PHP調用工作正常,但也許有另一種更清晰的方式來顯示相同​​的?如何優化php語法

<?php if ($this['modules']->count('top-a')) : ?> 
     <?php if ($this['config']->get('warp_onlyhome')) : ?> 
      <?php $catid = JRequest::getInt('catid'); if ($catid == 0) : ?> 
    <section id="top-a" class="grid-block"><?php echo $this['modules']->render('top-a', array('layout'=>$this['config']->get('top-a'))); ?></section> 
      <?php endif ?> 
      <?php else: ?> 
    <section id="top-a" class="grid-block"><?php echo $this['modules']->render('top-a', array('layout'=>$this['config']->get('top-a'))); ?></section> 
     <?php endif; ?> 
    <?php endif; ?> 
+2

'' –

+2

你問這樣的問題在這裏以前讀一本書或教程... – ducin

回答

1

您使用else:

<?php if ($this['config']->get('warp_onlyhome')) : ?> 
    <?php $catid = JRequest::getInt('catid'); if ($catid == 0) : ?> 

my content goes here 

    <?php endif: ?> 
    <?php else: ?> 

my content 2 

<?php endif; ?> 

減瘋狂格式:

if ($this['config']->get('warp_onlyhome')) { 
    $catid = JRequest::getInt('catid'); 
    if ($catid == 0) { 
     echo "my content goes here"; 
    } 
} else { 

    echo "my content 2"; 

} 
+0

謝謝!你的回答正是我需要的! – LifeIsShort

1

這是別人是否嵌入瞭如何使用的例子。

<? if ($condition): ?> 
    <p>Content</p> 
<? elseif ($other_condition): ?> 
    <p>Other Content</p> 
<? else: ?> 
    <p>Default Content</p> 
<? endif; ?> 

more examplealternative