通知消息(成功消息)

How do I create a notification message in codeigniter when data was saved in database (success message).?

Its just an example: controller:

    $result = $this->db->insert("users",$data)
    if($result){            
            $this->session->set_flashdata("success","Employee delete successfully");
            redirect("users_list");
    } else {
            $this->session->set_flashdata("error","Details not updated");
            redirect("new_users");
    }

views:

$flash_data = $this->session->flashdata();
// print_r($flash_data);
if(isset($flash_data["error"])){
    echo "<div class='alert alert-danger'><a href='#' class='close' data-dismiss='alert' aria-label='close'>&times;</a>". $flash_data["error"]."</div>";
} elseif (isset($flash_data["success"])) {
    echo "<div class='alert alert-success'><a href='#' class='close' data-dismiss='alert' aria-label='close'>&times;</a>". $flash_data["success"]."</div>";
}

hope this will solve your problem.

If you are using CI 3, you can utilize the flashdata in your controller/model.

$_SESSION['notif'] = 'Success!';
$this->session->mark_as_flash('notif');

Then in your view file

echo $this->session->mark_as_flash('notif');

If you are using CI 2, use json datatype in your ajax submit

$.ajax({
    type: 'post',
    dataType: 'json',
    data: 'data='+sample,
    url: 'URL',
    success: function(data)
    {
        if (data.success) {
            alert(data.success);
        }
    }
});

in your controller, you can do something like this

public function URL()
{
    $data = array('errors' => NULL, 'success' => NULL);

    $this->load->model('Yourmodel');
    $saveinModel = $this->Yourmodel->UrFunction();

    if ($saveinModel ) {
        $data['success'] = "Saved";
    } else {
        $data['errors'] = "Error";
    }
    echo json_encode($data);
}