0

我在将会话信息从一个函数传递到另一个函数时遇到问题。

public function xpto() {
       $this->load->library('session');
       $session_id = $this->session->all_userdata();
       $fb_pages = array(
            'fb_page' => $result_querypageidlink[0]['link']
       );
       $this->session->set_userdata($fb_pages);

       $this->load->library('fbconnect');
       $data = array(
            'redirect_uri' => site_url('main/handle_facebook_login_users'),
            'scope' => 'email, 
            user_birthday, 
            user_hometown, 
            user_location'
       );
   redirect($this->fbconnect->getLoginUrl($data));
}

'redirect_uri' 中调用的其他函数:

public function handle_facebook_login_users() {

$this->load->library('session');
$all_userdata = $this->session->all_userdata();

当我打印 $all_userdata 时没有显示我添加的信息和 xpto 功能。出于某种原因,当我添加会话信息(xpto 函数)并且如果我打印(在函数中,已经存在 - 所以它正在工作)但是当我在第二个函数中打印时,没有显示该信息。

4

1 回答 1

0

像这样设置会话:

$this->session->set_userdata('fb_page', $fb_pages);

像这样检索:

$fb_page = $this->session->userdata('fb_page');

编辑:

public function xpto() {
       $this->load->library('session');
       $session_id = $this->session->all_userdata();
       $fb_pages = array(
            'fb_page' => $result_querypageidlink[0]['link']
       );
       $this->session->set_userdata('fb_pages', $fb_pages); #set the session

       $this->load->library('fbconnect');
       $data = array(
            'redirect_uri' => site_url('main/handle_facebook_login_users'),
            'scope' => 'email, 
            user_birthday, 
            user_hometown, 
            user_location'
       );
   redirect($this->fbconnect->getLoginUrl($data));
}



public function handle_facebook_login_users() {
    $this->load->library('session');                     #Load the session in the autoload.php
    $fb_pages   = $this->session->userdata('fb_pages');  #retrieve the session
}
于 2013-10-04T11:54:12.940 回答