我正在开发cakephp 1.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 } ?>
答案 0 :(得分:0)
您应该在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);