1

I am new to the codeigniter framework, i am using flash messages it's displaying correclty but even after redirecting to another page still the same flash message is displaying for this issue i was trying to fix by following this accepted answer but still i am facing with this issue only, can you please help me did i miss anything..?

controller.php

$this->session->set_flashdata('msg','<p style="color:green;margin-left:40%;font-size:15px;">Book Added Successfully</p>');
            redirect('/books');

view.php

<?php echo $this->session->flashdata('msg'); unset($_SESSION['msg']);?>
sai sa
  • 171
  • 1
  • 5
  • Let's say you're on a main page, click a button to create a post, type up a post then click submit. You're redirected back to a main page. If the post was successful, we'd want to flash a message "Your post was created". The result of whether it was inserted into the database would be from before the redirect. Thus the usage of a flash message. If you're able to display the message already in the view, clearing the message afterwards is redundant since it would be cleared anyways. Also the view wouldn't be read if you're redirecting away. Only the view of the next page would be read. – Kevin Y Jul 20 '22 at 17:28
  • You might also be running into bug territory if you're on an older version: https://forum.codeigniter.com/thread-78596.html – Kevin Y Jul 20 '22 at 17:49
  • 1
    if you're doing it all correct, it should work. **Flash disappears only after the next refresh** – Abdulla Nilam Jul 22 '22 at 06:00

0 Answers0