多个复选框在蛋糕php [英] Multiple Check boxes in cake php
本文介绍了多个复选框在蛋糕php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一份预订清单,我想使用多个复选框将其删除。这是我的代码:
I have a list of bookings and I want to delete them using multiple checkboxes. Here is my code:
foreach ($bookings as $booking): ?>
<tr>
<td><?php echo h($booking['Booking']['first_name']); ?> </td>
<td><?php echo h($booking['Booking']['surname']); ?> </td>
<td><?php echo h($booking['Booking']['created']); ?> </td>
<td><?php echo $this->Form-> checkbox('Bookings.ID.['.$booking['Booking']['ID'].']',
array('value' => $booking['Booking']['ID']));?></td>
</tr>
<?php endforeach; ?>
,在我的控制器中,我使用此功能删除所选的预订:
and in my controller I use this function to delete the selected bookings:
public function deletebooking(){
$bookings = $this->Booking->find('all');
$this->set('bookings',$bookings);
if(!empty($this->data)){
foreach($this->data[Bookings] as $key => $value){
if($value != 0){
$this->Booking->delete($value);
$this->redirect(array('action' => 'index'));
}
}
}
}
任何人都可以告诉我为什么它不工作。
Can anyone tell me why it is not working?
推荐答案
将输入字段更改为:
foreach($ bookings as $ booking):?>
Change your input field to the following: foreach ($bookings as $booking): ?>
<td>
<?php echo $this->Form->checkbox('bookingids',
array(
'value' => $booking['Booking']['ID'],
'name' => 'data[Booking][bookingids][]',
));?>
</td>
请注意名称中的空白 []
值。这将创建该数组的新索引。在你的控制器中你可以这样访问它:
Notice the empty []
in the name value. This will create a new index of that array. In your controller you would access it like this:
if(!empty($this->data)) :
foreach($this->data['Bookings']['bookingids'] as $key => $value):
$data = array();
$data['Booking']['id'] = $value;
$this->Booking->delete($data);
endforeach;
$this->redirect(array('action' => 'index'));
endif;
这篇关于多个复选框在蛋糕php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文