![]() |
Session - Array of Array - 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: Session - Array of Array (/showthread.php?tid=51096) |
Session - Array of Array - El Forum - 04-20-2012 [eluser]soprabaixar1[/eluser] How do I work with array of array inside the session? For example, I have an array of various products. There is a button that when you click add these products in the session array, and the limit are up to six products. I just want to add more products in the session array and I can not. This array structure is actually just one example of what I really need. I'm doing so: Code: $products[] = array( Session - Array of Array - El Forum - 04-20-2012 [eluser]WanWizard[/eluser] Are you using the database or the cookie for your session? Cookies are very limited in size, if you store array structures in it, you run into the size limits quite easily. Session - Array of Array - El Forum - 04-20-2012 [eluser]soprabaixar1[/eluser] I'm not using database. Do not understand very well. The structure of the array is small. I think it would have no problem in size. Session - Array of Array - El Forum - 04-20-2012 [eluser]WanWizard[/eluser] You're talking about a "button that adds...", that is application specific. So if the application restricts you to 6 items, perhaps you have to modify that? Session - Array of Array - El Forum - 04-20-2012 [eluser]soprabaixar1[/eluser] WanWizard, Correct, this value (6) could be need to be modified. Researching, I found a comment in the forum talking about the class "cart" of the CodeIgniter and I'm doing some tests here using this algorithm: http://ellislab.com/codeigniter/user-guide/libraries/cart.html (The Adding Multiple Items to Cart) I did what I needed in part. The problem I am having is adding a new item in the array, I am using the function "array_push ()" PHP is that before I read the array in this session. But the problem that the structure of the array was broken, probably the logic I'm using. Not keeping the level of the structure of the array, the level of the array is coming down. Session - Array of Array - El Forum - 04-21-2012 [eluser]soprabaixar1[/eluser] I got, but how can I delete for example products['2'] and products['4']? This is not working: Code: $this->session->unset_userdata("products['2']"); Session - Array of Array - El Forum - 04-21-2012 [eluser]soprabaixar1[/eluser] Resolved!! The CI should support multi array delete the session, but from what I see does not support. The way you delete it as follows: Code: unset($this->session->userdata['products']['2']); I got following the algorithm of the function "unset_userdata" of WanWizard. On post: http://ellislab.com/forums/viewthread/158206/#763169 For add more products in the session array just follow the same logic above of the post #4 this topic. Session - Array of Array - El Forum - 04-23-2012 [eluser]soprabaixar1[/eluser] We really had a problem with the size and for resolve only changed the configuration of the session to work with database and created a table in the database, as follows documentation. |