0

I am unable to delete the data in codeiginter I am new to it so please help me....

my code for the view page is

<?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
}
?>

and my code for the controller is

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

and code for model is

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

2 に答える 2

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');
}
于 2013-04-01T12:21:48.623 に答える
0

.....を使用してみてくださいsite_url()。URLにIDを渡す必要があります

URL が変更された場合にページの移植性が向上するように、ローカル URL を生成する必要がある場合はいつでもこの関数を使用することをお勧めします。

更新しました

....
<td><?php echo anchor(site_url('admin_controller/delete_facility/'.$field->facility_id),'Delete','id="'.$field->facility_id).'"'?></td>
于 2013-04-01T12:33:58.017 に答える