首页 > 解决方案 > 无法使用href删除codeigniter中的记录

问题描述

我正在尝试使用 href 删除特定记录。但是当我单击按钮时它无法正常工作,它像这样传入 URL

http://localhost/project_x/Organisation/Organisation/%3C?php%20echo%20base_url();?%3EOrganisation/delete_org?id=3

我不知道错误在哪里,任何人都可以帮助我。它在 URL 中传递 id 是正确的。

这是我的控制器:

function delete_org() {
   // Pass the $id to the org_delete() method
      $this->Org_model->org_delete($id);
      redirect('Organisation/organisation');
}

这是我的重定向组织功能

public function organisation() {

    $data['organisations'] = $this->Org_model->getOrganisations();
    $this->load->view('template/header');
    $this->load->view("organisation", $data);
    $this->load->view('template/footer');
}

这是我的模型:

function org_delete($id) {
    $this->db->where('id', $id);
    $this->db->delete('organisation');
}

这是我的视图按钮:

<?php
echo "<td class='text-center'><div class='btn-group btn-group-xs'><a href='#' data-logid='" . $org->id . "' data-target='#editGroups' data-toggle='modal' title='Edit' class='open_modal btn btn-default'><i class='fas fa-edit'></i></a>";
echo "<a href='<?php echo base_url();?>/Organisation/delete_org?id=$org->id'  class='btn btn-danger confirmation'><i class='fas fa-times'></i></a></div></td></tr>";                                           
?>

谁能帮我在哪里做错了。

提前致谢。

标签: phpcodeigniterurl

解决方案


希望对你有帮助 :

像这样更改视图按钮:

<?php
echo "<td class='text-center'><div class='btn-group btn-group-xs'><a href='#' data-logid='" . $org->id . "' data-target='#editGroups' data-toggle='modal' title='Edit' class='open_modal btn btn-default'><i class='fas fa-edit'></i></a>";
echo "<a href='".base_url('Organisation/delete_org?id='.$org->id)."'  class='btn btn-danger confirmation'><i class='fas fa-times'></i></a></div></td></tr>";

在控制器中:

function delete_org() { 
      $id = $this->input->get('id');
      $this->Org_model->org_delete($id);
      redirect('Organisation/organisation');
}

推荐阅读