无法在codeigniter会话中存储数据

时间:2014-02-24 11:02:05

标签: codeigniter session

我正在尝试将数据存储在我的会话变量中,但我做错了。

我有以下代码:

       $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>";

第一个print_r返回:

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] => 
 )

第二个print_r只返回MySess(空数组)

,而第三个print_r返回以下内容:

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] => 
)

任何人都可以指出我在做什么变量$ sessionFormValues返回一个空数组?如何才能在单独的变量中获取formvalues数据?

问候,约翰

1 个答案:

答案 0 :(得分:1)

您的数据在会话中保存得很好,但问题是'formValues'密钥不存在。你需要改变

$this->session->set_userdata($formValues);

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