Welcome Guest, Not a member yet? Register   Sign In
Passing Data Between Views without saving it to cookies
#1

[eluser]Doulos[/eluser]
I'm working on a project that has a series of pages and on each page displays the data from the previous pages in a side bar.

The data I'm dealing with isn't data I want to put into a cookie and may, in some cases, be too large to do so anyway. But I also Want to hit the controller to check authentication and do some different redirecting depending on the type of user between each page.

So my question is how do I move the data between pages(each page has a controller function and several possible views)? Can I pass data to a controller so I could pass it back down to a view? If so, What's the syntax for the link from each page to the next to make the controller accept data?

Thanks!
#2

[eluser]marcogmonteiro[/eluser]
You can pass the data though session variable store in the database should be the more secure way. Since you already using authentication.
#3

[eluser]Doulos[/eluser]
So you're thinking the best way is to write two methods, one that stores the pieces of information and one that retrieves it and invoke them in each controller function?

I did think of this, but was worried about the database load/speed as it scales. Do you think there'd be an issue with speed using this method?

I'm going to go ahead and start developing this direction, but if anyone else has a suggestion or input on this approach's speed versus some other method I'd love to hear it.

Edit: Method = Model
#4

[eluser]marcogmonteiro[/eluser]
i don't know how big the data is, but you can just make an array of data like this:
Code:
$newdata = array(
                   'username'  => 'johndoe',
                   'email'     => '[email protected]',
                   'logged_in' => TRUE
               );

$this->session->set_userdata($newdata);


and then to retrive the data just use:

Code:
$this->session->userdata('username');

to use database with sessions in CI just check the userguide here:

http://ellislab.com/codeigniter/user-gui...sions.html

On the part that says saving session data in database.

this way you can retrive the data anywhere even directly in the view...
#5

[eluser]Doulos[/eluser]
Right, but the Data i'm working with could be larger than 4k, so I don't think storing it to the session will work unless there's a way to only post it to the sessions table and not the cookie. But at that point, I may as well just implement it myself like I talked about above, no?
#6

[eluser]marcogmonteiro[/eluser]
If that's the case, yes maybe that's better... I thought we were talking about much smaller data Smile
#7

[eluser]John_Betong_002[/eluser]
I do not know and cannot find the limitations but I think the following is worth investigating because it may save you a lot of coding:

Saving Session Data to a Database

http://ellislab.com/codeigniter/user-gui...sions.html

 
 
 
#8

[eluser]cideveloper[/eluser]
[quote author="Doulos" date="1308193189"]Right, but the Data i'm working with could be larger than 4k, so I don't think storing it to the session will work unless there's a way to only post it to the sessions table and not the cookie. But at that point, I may as well just implement it myself like I talked about above, no?[/quote]

You could implement it yourself but why? If you use session db it only stores the data in the db and the cookie holds an encrypted identifier that matches up with the db record.
#9

[eluser]Doulos[/eluser]
[quote author="cideveloper" date="1308216614"]
You could implement it yourself but why? If you use session db it only stores the data in the db and the cookie holds an encrypted identifier that matches up with the db record.[/quote]

Thanks, this confirmation helps. I still wasn't sure if the session data was stored in both places and therefore still limited. So I appreciate the feedback. I will just amend the sessions table to have extra fields and use the normal sessions stuff.

Appreciate the help!
#10

[eluser]Doulos[/eluser]
So I Implemented this and it doesn't appear that the Stock CI ($this->session->set_userdata()) saves custom Data to the DB table, only the cookie. So it doesn't appear that just using the stock stuff will work for my purposes.

Just FYI.

Anyone know off the top of their head if http://codeigniter.com/wiki/DB_Session/ works in the current version? Before I give it a shot?

Update: DB_Session doesn't work in 2.02

Trying http://codeigniter.com/wiki/EckoSession/ next.




Theme © iAndrew 2016 - Forum software by © MyBB