2013-01-20 69 views
2

所以我有這種形式來添加報告,我的報告有很多措施。我的問題是,我想將「度量」的顯示「拆分」爲組(度量屬於一個組)。多個輸入分組

我有這樣的:

//Controller/Report/add 

$measures = $this->Report->Measure->find('list'); 

這:

//View/Report/add.ctp 

echo $this->Form->input('Measure', array('label' => false, 'multiple' => 'checkbox')); 

此輸出:

<div class="input select"> 
    <input type="hidden" name="data[Measure][Measure]" value="" id="MeasureMeasure"/> 
    <div class="checkbox"> 
     <input type="checkbox" name="data[Measure][Measure][]" value="1" id="MeasureMeasure1" /> 
     <label for="MeasureMeasure1"> 
      ... 
     </label> 
    </div> 

     .... 
</div> 

不過,我需要這樣的東西:

<h2>Measure Group 1</h2> 
    <div class="input select"> 
     <input type="hidden" name="data[Measure][Measure]" value="" id="MeasureMeasure"/> 
     <div class="checkbox"> 
      <input type="checkbox" name="data[Measure][Measure][]" value="1" id="MeasureMeasure1" /> 
      <label for="MeasureMeasure1"> 
       ... 
      </label> 
     </div> 

      .... 
    </div> 
<h2>Measure Group 2</h2> 
    <div class="input select"> 
     <input type="hidden" name="data[Measure][Measure]" value="" id="MeasureMeasure"/> 
     <div class="checkbox"> 
      <input type="checkbox" name="data[Measure][Measure][]" value="1" id="MeasureMeasure1" /> 
      <label for="MeasureMeasure1"> 
       ... 
      </label> 
     </div> 

      .... 
    </div> 

達到此目的的最佳方法是什麼?

回答

1

這將需要一些額外的工作請求數據設置視圖時預填充字段進行編輯,但你可以做這樣的事情:

echo $this->Form->input('Measure.Measure.group1', array('options'=>$options, 'label' => false, 'multiple' => 'checkbox')); 
echo $this->Form->input('Measure.Measure.group2', array('options'=>$options, 'label' => false, 'multiple' => 'checkbox')); 

應該給你在你的控制器像這樣的東西:

pr($this->data['Measure']['Measure']['group1']); 

array(
    [0] => someval, 
    [1] => some other val 
) 
+0

謝謝你的回答,讓我解決了問題:) –

0

好了,所以我解決了這個問題,基本上我做:

$this->loadModel('Measuregroup'); 
$this->Measuregroup->contain(); 
$measureGroups = $this->Measuregroup->find('all'); 
foreach ($measureGroups as $measureGroup) { 
    $measures[$measureGroup['Measuregroup']['name']] = 
     $this->Report->Measure->find('list', 
      array('conditions' => array(
       'Measure.measuregroup_id' => $measureGroup['Measuregroup']['id']))); 
} 

而在此看來:

echo $this->Form->input('Measure', array('label' => false, 'multiple' => 'checkbox'));