Pass a variable between a controller - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Pass a variable between a controller (/showthread.php?tid=10370) |
Pass a variable between a controller - El Forum - 07-29-2008 [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 Pass a variable between a controller - El Forum - 07-29-2008 [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. Pass a variable between a controller - El Forum - 07-29-2008 [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. Pass a variable between a controller - El Forum - 07-29-2008 [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 Pass a variable between a controller - El Forum - 07-29-2008 [eluser]Tom Glover[/eluser] You could load the controllers in other controllers by using Wick (Controller Loader). Pass a variable between a controller - El Forum - 07-29-2008 [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. Pass a variable between a controller - El Forum - 07-30-2008 [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 Pass a variable between a controller - El Forum - 07-30-2008 [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! |