php代码在活动按钮上显示图标


php code to display icon on active button

我正在开发cakehp1.3..

我有来自数据库的按钮和值显示在按钮内部。

我只想在我的活动按钮上显示箭头图标。。

现在活动箭头图标显示在所有按钮中。。。forloop内部。

请帮我做这件事。。

下面是我的代码

 <?php
     foreach($modes as &$mo)
     { 
       $temp = "Road Vs "; $mo = strtolower($mo);
?>
  <li class="active">
    <input name="data[Customer][mode]" class="railbtn" type="submit" id="mode" value="<?php echo $temp.$mo; ?>">
    <span class="arrow">
       <?php echo $this->Html->image('red_arrow.png', array('alt' => '')); ?>
    </span>
 </li>
 <?php } ?>   

您应该在for循环中添加一个条件像这个

<?php
// you need to send button unique name to controller 
foreach($modes as &$mo)
     { 
       $temp = "Road Vs "; $mo = strtolower($mo);  ?>
      <li class="<?php echo ($mo == $selectedUniqueButtonID) ? 'active' : '' ?>">
        <input name="data[Customer][mode]" class="railbtn" type="submit" id="mode" value="<?php echo $temp.$mo; ?>">
        <?php if($mo == $selectedUniqueButtonID){ ?>
            <span class="arrow">
               <?php echo $this->Html->image('red_arrow.png', array('alt' => '')); ?>
            </span> 
        <?php } ?>
     </li>
 <?php 
} ?>

控制器代码

$selectedUniqueButtonID = $this->data['Customer']['mode'];
$this->set('selectedUniqueButtonID',$selectedUniqueButtonID);