dqc18251 2018-05-17 11:41
浏览 37
已采纳

无法使用href删除codeigniter中的记录

I am trying to delete particular record using href. But it's not working properly when i click on button its passing in URL like this

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

I don't know where is the mistake can anyone help me.It's passing id in URL is correctly.

Here is my controller:

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

here is my redirect organisation function

public function organisation() {

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

Here is my model:

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

And Here is my view buttons:

<?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>";                                           
?>

Can anyone help me where i did mistake.

Thanks in advance.

  • 写回答

4条回答 默认 最新

  • dreamfly0514 2018-05-17 11:48
    关注

    Issue is you are adding php tag again in echo. change your delete anchor tag as below:

     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>";
    

    Also in controller define $id

    function delete_org() {
       // Pass the $id to the org_delete() method
          $id = $_GET['id'];
          $this->Org_model->org_delete($id);
          redirect('Organisation/organisation');
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100