0

我有从数据库中删除行的控制器,例如:-

public function deletePost() {
    $events = new event_model();
    $ev_id=intval($_POST['ev_id']);

    $result = $events->deletePostWall($ev_id);      

}

模型是:-

function deletePostWall($ev_id) {
    $vales = array('ev_id' => $ev_id);
    $vales_comment = array('co_postid' => $ev_id);
    $query_done = $this->db->delete($this->table_name, $vales) or die (mysql_error());
    $query_done_comment = $this->db->delete('comment', $vales_comment) or die (mysql_error());
}   

现在这种方法效果很好,但是我需要在删除成功时向用户发送消息以表明删除已完成。

怎么能做到。

4

3 回答 3

0

模型

function deletePostWall($ev_id) {
    $vales = array('ev_id' => $ev_id);
    $vales_comment = array('co_postid' => $ev_id);
    $query_done = $this->db->delete($this->table_name, $vales) or die (mysql_error());
    $query_done_comment = $this->db->delete('comment', $vales_comment) or die(mysql_error());
   return $this->db->affected_rows();
}

控制器

public function deletePost() {

    $events = new event_model();  
    $this->data['message'] = '';

    if($this->input->post()) {

        $ev_id=intval($this->input->post('ev_id'));

        $result = $events->deletePostWall($ev_id);   

        if($result) {
            $this->data['message'] = "Deleted!";

        }
        else {
           $this->data['message'] = "Not Deleted!";
        } 
    }        

    $this->load->view('VIEW-NAME',$this->data);
}

看法

<html>
    <head>
    </head>
    <body>
        <h1><?php echo $message; ?></h1>
    </body>
</html>
于 2013-08-26T06:19:49.573 回答
0

你可以试试这个

在控制器中

public function deletePost() {
    $events = new event_model();
    $ev_id=intval($_POST['ev_id']);

    $result = $events->deletePostWall($ev_id);
    $this->session->set_flashdata('msg','Delete is done');
    redirect('controller_name/function_name','refresh');//redirect a function which loads your view.      

}

在视野中

<?php if($this->session->flashdata('msg')){echo $this->session->flashdata('msg');}?>
于 2013-08-25T08:10:46.043 回答
0

控制器:

public function deletePost() {
    $events = new event_model();
    $ev_id=intval($_POST['ev_id']);

    $result = $events->deletePostWall($ev_id);   

   if($result) {
        $this->data['success'] = "Deleted!";
        $this->load->view('VIEW-NAME',$this->data);    
    }   

}

方法:

function deletePostWall($ev_id) {
    $vales = array('ev_id' => $ev_id);
    $vales_comment = array('co_postid' => $ev_id);
    $query_done = $this->db->delete($this->table_name, $vales) or die (mysql_error());
    $query_done_comment = $this->db->delete('comment', $vales_comment) or die(mysql_error());
   return $this->db->affected_rows();
}

看法:

<html>
    <head>
        <title>title</title>
    </head>
    <body>
        <h1><?php if (isset($success)) {echo $success;}?></h1>
    </body>
</html>
于 2013-08-25T07:34:22.477 回答