Session question? |
[eluser]Jamongkad[/eluser]
Hey guys! I know this may sound quite basic but I was wondering how can one use session variables to pass data from one page to another. Like lets say I had multiple forms, the user would fill out data for page 1. Then he would jump to page 2 but still have the data store in a cookie from page 1, and so on and so forth. Until he reaches the final page where all of his data is summarized for him. And he sends it out as an email. Are there any examples of that type of usage? I mean are there best practices with regards to how to use Code Igniter for such a task?
[eluser]FuriKuri[/eluser]
Something like this: //to save data: $this->session->set_userdata('name','peter'); //to recover data: echo $this->session->userdata('name'); // this will print 'peter'.
[eluser]Jamongkad[/eluser]
[quote author="FuriKuri" date="1186611383"]Something like this: //to save data: $this->session->set_userdata('name','peter'); //to recover data: echo $this->session->userdata('name'); // this will print 'peter'.[/quote] Thanks! is this possible? I was thinking within this line. And where do I place this code? in the view file? Code: $this->session->set_userdata('name',$_POST['name']);
[eluser]FuriKuri[/eluser]
[quote author="Jamongkad" date="1186615056"][quote author="FuriKuri" date="1186611383"]Something like this: //to save data: $this->session->set_userdata('name','peter'); //to recover data: echo $this->session->userdata('name'); // this will print 'peter'.[/quote] Thanks! is this possible? I was thinking within this line. And where do I place this code? in the view file? Code: $this->session->set_userdata('name',$_POST['name']); Yeah this code works. Im using it in my project. You can place it where u want, controller or view. For example if you want to write the name of the user use <?=$this->session->userdata('name');?> in the view file. PS: Recheck my thread
[eluser]Michael Wales[/eluser]
Because of the multiple pages that will be storing data - and not wanting to bloat the session that much - I would just store it all within one variable. A comma-delimited list works nicely, then you can implode() and explode() till your hearts content.
[eluser]Jamongkad[/eluser]
[quote author="walesmd" date="1186640265"]Because of the multiple pages that will be storing data - and not wanting to bloat the session that much - I would just store it all within one variable. A comma-delimited list works nicely, then you can implode() and explode() till your hearts content.[/quote] Umm how do I go about coding that in? Sorry I'm kinda new to Code Igniter and PHP in general....is this what you're talking about? Code: view: Code: view2:
[eluser]Unknown[/eluser]
hey guy! you can use the session variables in any view or controller file. like this: Code: <?= $this->session->userdata('name'); ?> but if you have normal variables or arrays, what ever, you must turn over the data, most suitable, to the controller. like this: Controller test.php Code: <?php View test_output.php Code: Data: <?= $test; ?> and maybe a wee bit <b>html</b> It`s better to display the informations only in view files and the conditioning of the informations in controllers, models... greetz chichi |
Welcome Guest, Not a member yet? Register Sign In |