删除codeigniter中的数据

时间:2013-04-01 12:09:29

标签: php codeigniter

我无法删除codeiginter中的数据我是新手,所以请帮助我....

我的视图页面代码是

<?php
   foreach($item as $field)
   {
   ?>
   <tr>
       <td><?php echo $field->facility_id; ?></td>
       <td><?php echo $field->facility_name; ?></td>
       <td><?php echo $field->facility_desc; ?></td>
       <td>Edit</a></td>
       <td><?php echo anchor('http://localhost/Alaris_Health/index.php/admin_controller/delete_facility','Delete',$field->facility_id);?></td>
   </tr>
   <?php
}
?>

我的控制器代码是

function delete_facility($fac_id)
{
    $this->load->model('Admin_model');
    $this->Admin_model->remove_facility($fac_id);
    $this->load->view('facility_view',$data);
}

和模型的代码是

function remove_facility($fac_id)
{
     $this->db->delete('admin_facility_code', array('facility_id' => $fac_id)); 
}

2 个答案:

答案 0 :(得分:0)

而不是:

<?php echo anchor('http://localhost/Alaris_Health/index.php/admin_controller/delete_facility','Delete',$field->facility_id);?>

function delete_facility($fac_id)
{
    $this->load->model('Admin_model');
    $this->Admin_model->remove_facility($fac_id);
    $this->load->view('facility_view',$data);
}

试试这个:

<?php echo anchor('http://localhost/Alaris_Health/index.php/admin_controller/delete_facility/'.$field->facility_id.'','Delete','');?>

function delete_facility()
{
    $this->load->model('Admin_model');
    $fac_id = $this->uri->segment(5);
    $this->Admin_model->remove_facility($fac_id);
    $this->load->view('facility_view');
}

答案 1 :(得分:0)

尝试使用site_url() .....并且您需要在url中传递id

  

我们鼓励您在需要生成本地网址时使用此功能,以便在您的网址发生变化时您的网页变得更具便携性。

<强>更新

....
<td><?php echo anchor(site_url('admin_controller/delete_facility/'.$field->facility_id),'Delete','id="'.$field->facility_id).'"'?></td>