我有一个帖子列表,我想使用多个复选框删除它们。我在 cake php 中关注了这个链接Multiple Check boxes 但我得到了这个错误(我使用 cakephp 2.4):
未找到 PostsController::deleteSelect() 的视图。
确认您已创建文件:C:\xampp\htdocs\cakephp2\app\View\Themed\Cakestrap\Posts\delete_select.ctp
我想从 index.ctp 而不是 delete_select.ctp 访问这些数据。我的问题是我如何访问这些数据“data['Post']['box'][]”?
我的代码是:
索引.ctp
<?php foreach ($posts as $post): ?>
<tr>
<td><?php echo $post['Post']['id']; ?></td>
<td>
<?php echo $this->Html->link($post['Post']['title'], array('action' => 'view', $post['Post']['id'])); ?>
</td>
<td>
<?php echo $post['Post']['created']; ?>
</td>
<td>
<?php echo $this->Form->checkbox('post',
array(
'value' => $post['Post']['id'],
'name' => "data['Post']['box'][]",
));?></td>
<td>
<?php echo $this->Form->postLink(
'Delete',
array('action' => 'delete', $post['Post']['id']),
array('confirm' => 'Are you sure?'));
?>
<?php echo $this->Html->link('Edit', array('action' => 'edit', $post['Post']['id'])); ?>
</td>
</tr>
<?php endforeach; ?>
<p><?php echo $this->Html->link('deleteSelect', array('action' => 'deleteSelect')); ?></p>
删除选择功能
public function deleteSelect(){
if(!empty($this->data)) {
foreach($this->data['Post']['box'] as $key => $value){
$this->Post->delete($value);
}
$this->redirect(array('action' => 'index'));
}
}