duanlei1957 2014-02-25 16:03
浏览 36
已采纳

使用Codeigniter编辑和删除操作

i want to update and delete an entry im really new at this and i dont know where to put the function..so yeah i need help

controller

function delete()
{
    $this->site_model->delete_row('booking');
    $this->view();
}
}

site_model

function delete_row()
{
    $this->db->where('id', $this->uri->segment(3));
    $this->db->delete('booking');
}

and my view

<?php 
$this->table->set_heading("Name","Nationality","Number of Guest","Date","Package","Other      Request","Delete Record");
$qry = $this->db->get('booking');
foreach ($qry->result() as $row) {
$this->table->add_row($row->name,$row->nationality,$row->number_of_guest,$row->date,$row->package,$row->request);

}
echo $this->table->generate();

 ?>

TIA, im really new at this so please consider this..

  • 写回答

2条回答 默认 最新

  • doris20141022 2014-02-25 16:24
    关注

    Since you have no real question, I'll just give you a few hints before we close this.

    • database communication should happen in the model, not the view
    • I suggest you use ids instead of uri segments, especially when you're deleting something (see @Wlises' answer)
    • to load a view, use $this->load->view('view_name_here');
    • to create a delete button, you simply need to redirect browser to your delete method of your controller (something like: site.com/booking/delete/5, where 5 is the id of the booking) using a simple anchor, JavaScript redirection, form submit, etc...

    The bottom line is: please use the tutorial, it's very good and covers 99% of what you'd need: http://ellislab.com/codeigniter/user-guide/tutorial/

    UPDATE

    You can build your own table for more flexibility (and you're probably more comfortable with HTML rather than CI's helper functions). So, every row would need a delete button/link like this:

    <tr>
        <td><?php echo $row->name; ?></td>
        ... etc
        <td><a href="<?php echo base_url('booking/delete/' . $row->id); ?>">DELETE</a></td>
    </tr>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?