将类添加到cakephp(HABTM)中的所有复选框

时间:2014-03-26 11:07:00

标签: cakephp

我必须与HABTM相关联的表格,它会完美地显示复选框。代码行是这样的:

   <?php  echo $this->Form->input('Item.ItemCharacteristic',array('id'=>'item_characteristic','label' =>false,'type'=>'select','multiple'=>'checkbox','options' => $itemCharacteristics,'selected' => $this->Html->value('ItemCharacteristic.ItemCharacteristic')));
  ?>

它显示的是:

                       <div class="input select"><input type="hidden" name="data[Item][ItemCharacteristic]" value="" id="item_characteristic"/>

<div class="checkbox"><input type="checkbox" name="data[Item][ItemCharacteristic][]" value="8" id="item_characteristic8" /><label for="item_characteristic8">We-Fii</label></div>
<div class="checkbox"><input type="checkbox" name="data[Item][ItemCharacteristic][]" value="9" id="item_characteristic9" /><label for="item_characteristic9">Test1</label></div>
<div class="checkbox"><input type="checkbox" name="data[Item][ItemCharacteristic][]" value="10" id="item_characteristic10" /><label for="item_characteristic10">Setting</label></div>
<div class="checkbox"><input type="checkbox" name="data[Item][ItemCharacteristic][]" value="11" id="item_characteristic11" /><label for="item_characteristic11">Test4</label></div>
<div class="checkbox"><input type="checkbox" name="data[Item][ItemCharacteristic][]" value="13" id="item_characteristic13" /><label for="item_characteristic13">Solari</label></div>
<div class="checkbox"><input type="checkbox" name="data[Item][ItemCharacteristic][]" value="15" id="item_characteristic15" /><label for="item_characteristic15">Panorama</label></div>
<div class="checkbox"><input type="checkbox" name="data[Item][ItemCharacteristic][]" value="17" id="item_characteristic17" /><label for="item_characteristic17">BlusBrothers</label></div>
</div> 

所以我想要的是在iput元素中添加一个类,如下所示:

<div class="checkbox"><input type="checkbox" name="data[Item][ItemCharacteristic][]" value="8" id="item_characteristic8" class="element" /><label for="item_characteristic8">We-Fii</label></div>

所以只需要将class =“element”添加到它..

任何想法?

1 个答案:

答案 0 :(得分:1)

您可以通过添加'class'=&gt;将您的课程放在该字段上'name'到数组

 <?php  echo $this->Form->input('Item.ItemCharacteristic',array('class'=>'mycustomclass' 'id'=>'item_characteristic','label' =>false,'type'=>'select','multiple'=>'checkbox','options' => $itemCharacteristics,'selected' => $this->Html->value('ItemCharacteristic.ItemCharacteristic')));
  ?>

我希望它能解决你的问题