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 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么