CodeIgniter Forums
Appending to session 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: Appending to session array (/showthread.php?tid=50231)



Appending to session array - El Forum - 03-19-2012

[eluser]Unknown[/eluser]
In my core controller I'm trying to create an array of the user's history. I am creating an array and then setting the key as the time and the value as the page URL. However the problem that I'm having is that the previous array seems to get overwritten so there is only ever one key and value pair in the array.

How can I do it so that instead each page will get appended to the array

Code:
$history = array(
    time() => curPageURL()
);

$this->session->set_userdata('history', $history);

Thanks for any help


Appending to session array - El Forum - 03-19-2012

[eluser]Krzemo[/eluser]
Code:
$history = $this->session->userdata('history');
$history[] = array(time() => curPageURL());
$this->session->set_userdata('history', $history);
I hope you are using database sessions for that. I also have no idea for how long you are going to keep that history, but I'd keep it in a sessions data only if there are going to be no more then just few items in the array...