Reputation: 693
I am trying to store data in my session variable, but i am doing something wrong obviosly.
I have the following code:
$formValues = $this->input->post(NULL, TRUE);
echo "Form<pre>";
print_r($formValues);
echo "</pre>";
$this->session->set_userdata($formValues);
$sessionFormValues = $this->session->userdata('formValues');
echo "MySess<pre>";
print_r($sessionFormValues);
echo "</pre>";
echo "Sess<pre>";
print_r($this->session->all_userdata());
echo "</pre>";
The first print_r returns:
Array
(
[addtypeid] =>
[isnew] =>
[orderby] =>
[geographicareaid] =>
[catid] => 1
[catid2] =>
[manufacturerid] =>
[modelid] =>
[yearofmanufacturing_from] =>
[yearofmanufacturing_to] =>
[hoursused_from] =>
[hoursused_to] =>
[horsepowers_from] =>
[horsepowers_to] =>
[price_from] =>
[price_to] =>
[colorid] =>
[isdamaged] =>
)
The second print_r returns just MySess (empty array)
while the third print_r returns the following:
Array
(
[session_id] => 639ca0b53c8e68cda4e6d61605c4d227
[ip_address] => 94.68.157.85
[user_agent] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.117 Safari/537.36
[last_activity] => 1393239192
[user_data] =>
[addtypeid] =>
[isnew] =>
[orderby] =>
[geographicareaid] =>
[catid] => 1
[catid2] =>
[manufacturerid] =>
[modelid] =>
[yearofmanufacturing_from] =>
[yearofmanufacturing_to] =>
[hoursused_from] =>
[hoursused_to] =>
[horsepowers_from] =>
[horsepowers_to] =>
[price_from] =>
[price_to] =>
[colorid] =>
[isdamaged] =>
)
Anyone can point me what I am doing variable $sessionFormValues returns an empty array? How can i get only the formvalues data in a separate variable?
Regards, John
Upvotes: 0
Views: 88
Reputation: 6014
Your data is getting saved in the session fine but the problem is that the 'formValues'
key doesn't exist. You need to change
$this->session->set_userdata($formValues);
to
$this->session->set_userdata('formValues', $formValues);
Upvotes: 1