php - 无法使用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>";
?>
谁能帮我在哪里做错了。
提前致谢。
解决方案
希望对你有帮助 :
像这样更改视图按钮:
<?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');
}
推荐阅读
- javascript - 如何发生点击功能不是div而是按钮
- javascript - Firestore 查询函数结果无效
- java - 对如何在 Java 中使用数组中的索引和值感到困惑
- pouchdb - 找不到 express-pouchdb 相关模块
- r - R中的if_else双重标准条件
- linux - Spring框架升级
- matlab - 如何通过单击图中相应的绘图点来选择 UITable 中的单元格?
- angular - identityserver4 添加 api 资源导致未经授权的请求
- windows - 像 GDB 这样的调试器如何能够一次运行一条指令?
- ios - 将 Native 阴影反应到顶部以提供类似“架子”的效果