im having problems starting a codeigniter project, the problem is that when i do something in a controller and then i want a page to display the result, an example: i have a form to add a item to the database, i get all the data in the controller and save it to database and then i want (if all went well) to redirect to the main page with a success msg, i was doing this with
$this->load->view('admin', $data);
the problem is that the url keeps saying admin/addItem so everytime the page gets refreshed it adds another item, now i found the:
redirect('admin','refresh');
but this only helps me when i dont need to display any msg because this function dont allow to send a $data var.
Any ideas?
Probably this is really easy to fix but i cant find a way to handle the flow of the application the way i want, any help is apreciated.
thanks 😉
Flashdata is your friend, follow that link and about halfway through the page you’ll find the docs for flashdata.
Basically if your form functions are successful you set flashdata with your success message,
$this->session->set_flashdata('success', 'You successfully did something, yay!');Now redirect to your admin page.
redirect('admin','refresh');on your admin page check for existing flashdata and echo it to the user