Welcome Guest, Not a member yet? Register   Sign In
Accessing a session from a model
#1

[eluser]medvind[/eluser]
I'm trying to make a shopping cart in CI. A model called "cart" contains the products in the shopping cart, reads from and writes to the session variable.

Now, it seems the session variable isn't saved properly when I write to it from the model. When writing to it from the controller, though, it works. Is this "normal"? Are you not supposed to access the session from the model? Otherwise something is wrong with my code.

Maybe the problem is that I save an array of objects into the session variable?
#2

[eluser]sl3dg3hamm3r[/eluser]
It won't matter if you read/write from a controller or a model. There might be an issue with your code then. How do you use sessions? Do you use DB-driven sessions, or cookie only? Bear in mind that if you don't use DB, you are limited to about 2KB session-data.
#3

[eluser]medvind[/eluser]
Thanks for your reply!
I use cookies. That might be the issue. Maybe I should not save the products as objects in the session variable...
#4

[eluser]sl3dg3hamm3r[/eluser]
Yeah - large arrays aim for a DB-driven session. It's quite easy to change.
#5

[eluser]medvind[/eluser]
[quote author="sl3dg3hamm3r" date="1251138412"]Yeah - large arrays aim for a DB-driven session. It's quite easy to change.[/quote]

Thanks for the tip. I'm thinking maybe it's unnecessary to save the entire objects anyway, though.
#6

[eluser]jedd[/eluser]
Btw, you may want to investigate the new CodeIgniter Cart library.

It's only available in CVS at the moment, but this shouldn't stop you from using it (IMHO).

Official Subversion repository : [url="http://dev.ellislab.com/svn/CodeIgniter/trunk/"]http://dev.ellislab.com/svn/CodeIgniter/trunk/[/url]

Or if you're a fan of the light side, replicated over at [url="http://github.com/cbosuna/codeigniter"]GitHub[/url]
#7

[eluser]medvind[/eluser]
[quote author="jedd" date="1251140695"]Btw, you may want to investigate the new CodeIgniter Cart library.

It's only available in CVS at the moment, but this shouldn't stop you from using it (IMHO).

Official Subversion repository : [url="http://dev.ellislab.com/svn/CodeIgniter/trunk/"]http://dev.ellislab.com/svn/CodeIgniter/trunk/[/url]

Or if you're a fan of the light side, replicated over at [url="http://github.com/cbosuna/codeigniter"]GitHub[/url][/quote]

Oh, thanks! I didn't know this existed. I will take a look.




Theme © iAndrew 2016 - Forum software by © MyBB