使用cakephp选择jquery脚本 - 尝试从数据中保存数组

时间:2013-04-09 21:04:04

标签: php cakephp jquery-chosen

我正在尝试在我的“Requestc”控制器上保存一个包含Multiselect所选脚本数据的数组。

我的观点:

<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”时,它仍然是空白的。

enter image description here

2 个答案:

答案 0 :(得分: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,
 );

不在我的电脑后面进行测试,但认为应该没问题

答案 1 :(得分:0)

我认为您需要使用不同的语法来修改数据。 Check the cookbook

// Modify some request data, so you can prepopulate some form fields.
$this->request->data('Post.title', 'New post')
    ->data('Comment.1.author', 'Mark');