Please help with session - 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: Please help with session (/showthread.php?tid=49895) |
Please help with session - El Forum - 03-06-2012 [eluser]ppwalks[/eluser] I have been stuck on this session error for a day now and have tried a million different techniques to try and solve it. Basically when the session is empty or a new request to the page there is no data in the session variable which means as I load the page it is giving the following errors: Message: Undefined index: totalprice Filename: main/cart.php Line Number: 4, Severity: Notice Message: Undefined index: cart Filename: main/cart.php, Message: Undefined index: cart Filename: controllers/welcome.php Line Number: 79, It is the code from the wrox book professional codeigniter, i have already read the posts on here but they do not answer my problem I have tried again and again but still nothing so someone please help on this one.. Controller Code: function cart($productid = -1) { Model Code: function updateCart($productid,$fullproduct){ So if anyone has a clue please enlighten me... If you add a product to the cart the error then stops as it has started a valid session with the variables inside.. Not had a great deal of experience dealing with session data so if some kind person would point me in the right direction I would be ever so grateful... Thanks in advance Paul Please help with session - El Forum - 03-06-2012 [eluser]CroNiX[/eluser] The proper way would be to check for the session variable before doing anything with it, just like you should with any other variable that may or may not be present. Code: if ($this->session->userdata('key') !== FALSE) However, you are using a mixture of CI's session class and PHP Native Sessions (WHY???), so you need to do the same type of thing except checking to see if your session variable isset() before trying to use it. This doesn't really have anything specific to do with CI, but rather trying to use PHP variables that may not be set. Please help with session - El Forum - 03-07-2012 [eluser]ppwalks[/eluser] Can you explain a little further I am new to php also, how would this apply to the current script? Thanks Please help with session - El Forum - 03-07-2012 [eluser]Ivoo[/eluser] Code: $_SESSION This is how CodeIgniter wants you to deal with session. Please help with session - El Forum - 03-07-2012 [eluser]ppwalks[/eluser] I understand its a global variable, but when I tried to add it into an if statement all i get is a foreach error which I cannot seem to rectify, hense why I asked for an example to demonstrate where I am going wrong. Forgive me if this sounds patronising but isn't that how people learn construct. |