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>

实现这一目标的最佳方法是什么?

4

2 回答 2

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
)
于 2013-01-20T10:50:22.837 回答
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'));
于 2013-01-20T17:27:20.233 回答