CakePHP复选框选择行


CakePHP Checkbox Selecting the row

我正在尝试使一个复选框选中表行。并将其传递给另一个控制器。但它只通过了1个复选框。

在我的视图中。ctp

<table>
    <thead>
        <th>ID</th>
        <th>Name</th>
        <th>Action</th>
        <th>select</th>
    </thead>
    <?= $this->Form->create('test', ['id' => 'test' , 'method'=>'POST', 'url'=>'/encomendas/fastadd']) ?>
    <?php foreach ($items as $item): ?>
        <tr>
            <td><?= h($item->id) ?></td>
            <td><?= h($item->name) ?></td>
            <td><?= h($item->action) ?></td>
            <td>
            <?= $this->Form->checkbox('select', ['value' => '1']);?>
            <?= $this->Form->hidden('id', ['default' => $item->id]);?>
            </td>
        </tr>
    <?php endforeach; ?>
    <?= $this->Form->button('send') ?>
    <?= $this->Form->end(); ?>
</table>

在中

debug($this->request->data());

它只返回1个值。

您必须传递select数组才能获得所有复选框值,如:

   <?= $this->Form->checkbox('select.', ['value' => '1']);?>

     <?= $this->Form->checkbox('select[]', ['value' => '1']);?>

通过这种方式,您可以获得所有的值。