0

我已经阅读了很多这样的帖子,但未能找到我的特殊情况。尝试删除选中的复选框。现在您可以提交表单,它会将您带到所有正确的页面,但实际上并没有删除任何内容。

这是我的控制器信息

function deleteFolder() {
   if(array_key_exists('deleteMe',$_POST)) {
      $checkbox = $this->input->post['checkbox']; 
      $this->index_model->deleteFolder($checkbox);
   }
 $this->folderdeleted();
}

这是我的模型

function deleteFolder($checkbox) {
  $this->db->where('folderName', 'folderName'); 
  $this->db->delete('senior', $checkbox);
return;
}

这是我的看法

<!DOCTYPE html>
<?php $this->load->view('partials/page_head'); ?> 
<body>
  <div id="container">
    <div id="top">
      <div class="topcenter">
       <h2><a class="homebtn" href="<?php echo base_url();?>">Home</a></h2>
      </div>
      <div class="navdescription"><span>Delete Page</span></div>
    </div>
      <div class="projectFolders">
      <?php foreach($foldername as $row) { ?>
        <div class="folder">
          <button><?php echo $row->folderName; ?></button>
          <div class="delete">
            <form name="delete" method="post" action="<?php echo base_url(); ?>index.php/home/folderdeleted">    
              <p>
                <input type = "checkbox" id = "check_<?php echo $row->folderName; ?>"/>
                <?php echo form_submit('deleteFolder', 'Delete'); ?>
              </p>
          </form>
          </div>
        </div>
      <?php } ?>
    </div>
  </div><!-- End of container div -->
</body>
</html>
4

1 回答 1

0

您的代码中有几个错误。我不确定我是否找到了所有这些以及代码是否有效。

控制器应该是:

function deleteFolder() {
   if($this->input->post('checkbox') !== false) {
      $checkbox = $this->input->post('checkbox');
      $this->index_model->deleteFolder($checkbox);
   }
 $this->folderdeleted();
}

模型应该是:

function deleteFolder($checkbox) {
  $this->db->where('folderName', $checkbox); 
  $this->db->delete('senior');
return;
}

视图中的输入标签应该是:

                <input name="checkbox" value="<?php echo $row->folderName; ?>" type = "checkbox" id = "check_<?php echo $row->folderName; ?>"/>

对复选框的一点警告:如果未选中它们,您将不会在 $_POST 变量中找到任何内容。

于 2013-02-07T18:25:46.390 回答