1
votes

Is there a way to set css to codeigniter session flashdata. I want to give success or error message when user is redirected from controller to view after success or error. Suppose

In controller

$this->session->set_flashdata("msg", "<div class='alert alert-success'> Data successfully inserted.</div>");
redirect("contoller/method");

In view

echo $this->session->flashdata("msg");

In this case I get success alert of bootstrap. But I need to make div in all set_flashdata and its to lengthy process. I want to know, If its possible to send third parameter to flashdata thats help to know if its error flashdata or success flash and accordingly show bootstrap success or error alert. Any help would be greatfull.

2

2 Answers

1
votes

If I understand your request well, you should dedicate value to variable regarding insert process. Than you should set flashdata. Something like:

$insert = $this->Some_model->insert($data);
if ($insert != false) {//or any controll you could make in model method return
    $msg = "<div class='alert alert-success'> Data successfully inserted.</div>";
} else {
    $msg = "<div class='alert alert-danger'> Error while inserting. Please try again.</div>";
}
$this->session->set_flashdata("msg", $msg);
0
votes

You can't use it that way... session->set_flashdata is cleared every time you use a redirect() method. I suggest you create a message helper and detect the status in the URI and show the message.

Example:

http://myhoe.com/save/succes

if you see succes in your URI the show the message.

Another suggestion is use AJAX.

:)