EllisLab text mark
Advanced Search
     
How to keep flash data in Codeigniter?
Posted: 19 January 2011 11:16 PM
Avatar
Joined: 2008-05-18
95 posts

I’ve a controller with a method there it catch an argument and set it in a flash var.

The question is…if i send many arguments to this method, using multiple firefox tabs but the same user session, could them get mixed or rewrited?

I mean, if i open a tab and send the “x” argument and is saved in a flash var and in another tab i send the argument “y” and is “x” rewrited by “y” or is handled like two different things? (i’m using stored sessions)

Also i’m having troubles keeping flash data. It don’t keep for next use if i change between sections. If i go to modify/general the flashdata is deleted (replaced by 0).

My code:

function modify(){
    $section 
$this->uri->segment(3);

    switch (
$section{
        
case 'identity':
                
$this->session->keep_flashdata('item');
                
$this->_modify_identity();
            break;
        case 
'general':
                
$this->session->keep_flashdata('item');
                
$this->_modify_general();
            break;
        case 
'print':
                echo 
$this->session->flashdata('item');
            break;
        default:
                if(
is_numeric($section)){
                    $this
->session->set_flashdata('item'$section);
                
}
                redirect
('profile/modify/identity');
            break;
    
}
 
Posted: 29 January 2011 09:39 PM   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2008-05-18
95 posts

Lol nobody can answer this?

 
Posted: 30 January 2011 02:58 AM   [ # 2 ]   [ Rating: 0 ]
Joined: 2010-10-14
49 posts

Why are you using flashdata instead of sessiondata if you need to save the data?

 
Posted: 30 January 2011 10:24 AM   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2008-05-02
383 posts

The question is…if i send many arguments to this method, using multiple firefox tabs but the same user session, could them get mixed or rewrited?

The sessions are overwritten!

Also i’m having troubles keeping flash data. It don’t keep for next use if i change between sections. If i go to modify/general the flashdata is deleted (replaced by 0).

Please, post the code of the _modify_general() method;


Cristian Gilè

 
Posted: 30 January 2011 11:17 AM   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2008-05-18
95 posts

_modify_general() method dont contain anything that could remove the flash data. Also i’ve tried removing that line and still dont work.

 
Posted: 30 January 2011 12:01 PM   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2008-05-02
383 posts

According to the code and your explanation:

1. You set a flash session var called ‘item’ ($this->session->set_flashdata(‘item’,‘some value’))
2. You redirect to modifiy() method
3. You switch the section (third uri segment), and if it is ‘identity’ or ‘general’ you keep the flash data for a next request

So, in the _modify_general() method, you call a new redirect. Right?


Cristian Gilè

 
Posted: 31 January 2011 09:48 PM   [ # 6 ]   [ Rating: 0 ]
Avatar
Joined: 2008-05-18
95 posts

_modify_general() is a simple form validation, is data is submited then it clears the flashdata and redirects the user.

The problem is that the flash data is cleared before, only in the menu switch. I mean if i remove that line and switch between “links” (method swithc) it is cleared or simply dont keep it.

Of flash data only is keeped on redirects? not in user clicks?

 
Posted: 31 January 2011 10:28 PM   [ # 7 ]   [ Rating: 0 ]
Avatar
Joined: 2009-06-19
6707 posts

Everytime you open a new tab it is a new window!

And for every new window the session stuff is assigned
a new session_id etc.

InsiteFX

 Signature 

Certified State of CT Computer Programming Teacher.
Custom Designed Icons, eBook Covers Software Boxes. CD, DVD Etc. New iPhone® Tab Bar Icons and iPhone® Applications Icons.

Skype: insitfx

STOP! Before posting your questions, remember the WWW Golden rule:
What did you try? What did you get? What did you expect to get?

Input -> Controller | Processing -> Model | Output -> View

 
Posted: 31 January 2011 10:31 PM   [ # 8 ]   [ Rating: 0 ]
Avatar
Joined: 2008-05-18
95 posts
InsiteFX - 01 February 2011 03:28 AM

Everytime you open a new tab it is a new window!

And for every new window the session stuff is assigned
a new session_id etc.

InsiteFX

But…i’m using keep_flashdata(‘item’)...this should keep the current data IF i don’t open another window but it don’t work.

 
Posted: 31 January 2011 11:53 PM   [ # 9 ]   [ Rating: 0 ]
Avatar
Joined: 2009-05-17
1444 posts
Sein Kraft - 01 February 2011 03:31 AM
InsiteFX - 01 February 2011 03:28 AM

Everytime you open a new tab it is a new window!

And for every new window the session stuff is assigned
a new session_id etc.

InsiteFX

But…i’m using keep_flashdata(‘item’)...this should keep the current data IF i don’t open another window but it don’t work.

You should check your server access log for requests. All it takes is one request, even a 404 from an image file that didn’t exist, and the flash data is gone.

 Signature 

Brian
Brian’s Web Design - Temecula
Community Auth - CodeIgniter Authentication Application