如何将数组传递给codeigniter中的会话

时间:2014-05-21 05:55:01

标签: php codeigniter

我在codeigniter会话中存储数组时遇到问题。这是我的代码

new_results会话似乎无法正常工作

$this->session->set_userdata(array('search' => $q));
$search = $this->session->userdata('search');
$current = $this->session->userdata('q');
$new_results= $this->session->userdata('new_results');
if($search==$current)
{
    $new_results = $this->session->userdata('new_results');
    print_r($new_results);
}
else
{
    $this->session->set_userdata(array("q" => $search));
    $start = 0;
    $results = array();
    $query = $q . " (site:vodlocker.com OR site:vidbull.com OR site:putlocker.com/embed OR site:putlocker.com/file OR site:sockshare.com/file OR site:sockshare.com/embed)";
    while($start<=100){
        $snoopy = new Snoopy;

        $googleurl = "http://www.google.com/search?q=".urlencode(trim($query))."&start=".$start;

        $snoopy->fetchlinks($googleurl);
        $result = $snoopy->results;
        foreach($result as $row)
        {
            if(!in_array($row, $results))
                $results[] = $row;
        }
        $start+=10;
    }
    $this->session->set_userdata(array("new_results" => $results));
    $new_results = $this->session->userdata("new_results");
    print_r($this->session->userdata("new_results"));

}

1 个答案:

答案 0 :(得分:4)

您可以这样做:

$newdata = array(
               'username'  => 'johndoe',
               'email'     => 'johndoe@some-site.com',
               'logged_in' => TRUE
           );
  $this->session->set_userdata($newdata);

欲了解更多信息,请访问此链接: http://ellislab.com/codeigniter/user-guide/libraries/sessions.html