从 select cakephp 获取多个值时出错

Error while getting multiple values from select cakephp

我正在尝试获取多个值以将它们存储在 cakephp 3.x 的数据库中,但我无法获取我 select 的所有值。就一个。

在我看来:

<select name="internalDestinations[ids]" id="internalDestinations-ids" multiple="true" class="...">
<?php
    foreach ($users2 as $i): ?>
       <option value="<?= $i['email'] ?>"> <?= $i['email'] ?> </option>
    <?php endforeach; 
    ?>
</select>   

在我的控制器中:

if($this->request->is('post')){
     $alarm->internalDestinations=$this->request->data['internalDestinations']['ids'];
     $this->log($this->request->data['internalDestinations']);
}

而且 select我输入的项目不止一个,我只得到一个:

Array
(
     [ids] => xxxxxxx@xxxxx.xxx
)

有什么帮助吗? 非常感谢

你可以简单地做

name="internalDestinations[ids][]" 

但为什么不使用 FormHelper

//first of all let's create an array with email both in the keys and in the values

$users3 = Cake\Utility\Hash::combine($users2, '{n}.email', '{n}.email');

// then let's use cake dotted notation to create arrays

<?= $this->Form->input('internalDestinations.ids', [
        'type' => 'select', 
        'multiple' => true, 
        'options' => $users3
    ]); ?>