Pass a variable between a controller |
[eluser]Taff[/eluser]
Is it possible (or advisable) to pass variables between controllers? I have one controller which I am using to upload a file to the server. After it has been uploaded I would like that variable accessible via my parse_csv controller so this is roughly what I have: Code: class Katalog extends Controller { Sorry for the silly question, I can't find anything in the forum about it which is probably down to me being the only one who doesn't know how to do it. Thanks for any help! Taff
[eluser]Adam Griffiths[/eluser]
I'm not quite sure if this is what you're after, but maybe you can use flashdata? In the session library.
[eluser]Jilani Jidni[/eluser]
[quote author="Taff" date="1217346497"] Code: class Katalog extends Controller { its not clear when you call this parse_csv. if you call this function at the end of upload_csv then try this Code: class Katalog extends Controller { otherwise use session.
[eluser]Taff[/eluser]
Thank you both for your answers. I had already tried both of the examples you mentioned. I was hoping there was a way to avoid using sessions. Taff
[eluser]Tom Glover[/eluser]
You could load the controllers in other controllers by using Wick (Controller Loader).
[eluser]Pascal Kriete[/eluser]
Wacky, the function is in the same controller - no need for [strike]ugly[/strike] alternative solutions. The easiest way to do this, is to just call that function after you upload and a) pass the data as a parameter, or b) put it in a class variable (as you're doing now). Code: $this->parse_csv($data); If you're going to display a link that the user has to click - that's two requests, you need to either store the data in a file, db, or the session. If you're using CI sessions, putting it into the session cookie would be mighty redundant, since the user just uploaded the file to the server. FWIW, I would ask if they want to parse it in the upload form, instead of showing a link as an afterthought.
[eluser]Taff[/eluser]
Thank you all for your replies. The resaon I wanted it to be a link is that the entire process involves a lot of links, and I was worried about getting timed out, but maybe simply passing the data as a parameter is the best solution. I think I am missing something...the code that I'm using in my original post $this->csv_file Is empty when I try to target it in parse_csv even though I am giving it a value in upload_csv...is this correct? Thanks again, Taff
[eluser]Tom Glover[/eluser]
[quote author="inparo" date="1217384452"]Wacky, the function is in the same controller - no need for [strike]ugly[/strike] alternative solutions. The easiest way to do this, is to just call that function after you upload and a) pass the data as a parameter, or b) put it in a class variable (as you're doing now). Code: $this->parse_csv($data); Thanks for the advice! |
Welcome Guest, Not a member yet? Register Sign In |