Search code examples
phpjquerycodeignitercodeigniter-flashdata

Why session flashdata message is being cleared in codeigniter?


First of all, I would like to share that I am calling api while unloading the page.

So here what is happening.

When I submit the form below things are happening. 1. from submit data is being sent to server and data is being saved to database. 2. and once page is about to unload another api is being called (using sendBeacon method) and again it will do some operation.

Above action are being executed respectively in given order. so whatever flashdata i am setting at the end of 1st action, is not coming to view page.

Please guide me how to bring session flashdata to view page.

This is what i am thinking

As second request is being made using sendBeacon method and it is being executed after edit or whatever function called on page submission so setting flashdata message is not working on redirection

Let me know what to do to get the flashdata message on redirected page.


Solution

  • Using keep_flashdata method in additional request, i am able to user flashdata message in redirected page.

    below is my code in additional request.

    if($this->session->flashdata('success')) 
    {
        $this->session->keep_flashdata('success');
    } 
    else if($this->session->flashdata('failure')) 
    {
        $this->session->keep_flashdata('failure');
    }