0

我试图在我的“Requestc”控制器上保存一个数组,其中包含来自多选所选脚本的数据。

我的观点:

<select data-placeholder="Selecione as certidões" name="certidoes[Requestc][][caminho]" multiple="multiple"  style="width:400px;" class="chzn-select">
    <?php foreach ($certidao as $certidoes): ?>
    <option value="<?php echo $certidoes['Certificate']['id']; ?>"><?php echo $certidoes['Certificate']['nome']; ?></option>
    <?php endforeach ?>
</select>

我的控制器:

if(!empty($solicitacao)) {
        $this->request->data['Requestc']['request_id'] = $this->Request->id;
        $data = $this->request->data['certidoes'];
        $this->Request->Requestc->saveAll($data['Requestc']);
    }

当我保存我的“request_id”时,它仍然是空白的。

在此处输入图像描述

4

2 回答 2

1

不是答案,而是说明如何使用 FormHelper 创建此输入;

// Aparently, this variable is not formatted correctly to be used
// directly for options. If possible, use Model::find('list')
// to get it in the right format
$options = array();

foreach ($certidao as $row) {
    $options[$row['Certificate']['id']] = $row['Certificate']['nome'];
}


echo $this->Form->input('Requestc.caminho', array(
    'type' => 'select',
    'multiple' => 'multiple',
    'data-placeholder' => 'Something here',
    'style' => 'width:400px',
    'class' => 'chzn-select',
    'options' => $options,
 );

不在我电脑后面测试,但觉得应该没问题

于 2013-04-09T21:49:45.450 回答
0

我认为您需要使用不同的语法来修改数据。检查食谱

// Modify some request data, so you can prepopulate some form fields.
$this->request->data('Post.title', 'New post')
    ->data('Comment.1.author', 'Mark');
于 2013-04-09T21:08:33.413 回答