2017-09-13 6 views
0

メソッドにajaxリクエストを介して取得したデータを保存し、後で別のメソッドを呼び出すときに取得する必要があります。コードシニターとのセッションでデータストアを取得する

public function updateInt() 
{ $this->load->library('session'); 
    $interval = $this->input->post('_interval'); 
    $aInt = array('my_interval' => $interval); 
    $this->session->set_userdata('post', $aInt); 
    $_interval_ = $this->session->userdata['post']['my_interval']; 
    return $_interval_; 
} 



public function getInt() 
    { 
     $interval = $this->updateInt(); 
     // print $interval and do some stuff !! 
    } 

//これは、NULLを返しますが、私は値がユーザーによってフロントエンドに設定し、updateInt()メソッドへのAJAX呼び出しで渡される必要があります。 私はcodeignterで初心者ですので、私はいくつかの助けが必要です。

答えて

1

あなたがしていることを確認してくださいセッションフォルダのアクセス許可に0700

を作るパスヌル保存

$config['sess_driver'] = 'files'; 
$config['sess_cookie_name'] = 'ci_session'; 
$config['sess_expiration'] = 7200; 
$config['sess_save_path'] = APPPATH . 'cache/session/'; 
$config['sess_match_ip'] = FALSE; 
$config['sess_time_to_update'] = 300; 
$config['sess_regenerate_destroy'] = FALSE; 

を、セッションを残していない、あなたのconfig.phpの中にあなたのセッションを設定していることを確認してください正確な投稿データを取得すること

public function updateInt() 
{ 
    // You can autoload it in config/autoload.php saves loading every page 
    $this->load->library('session'); 

    $aInt = array('my_interval' => $this->input->post('_interval')); 

    $this->session->set_userdata('post', $aInt); 

    // Use `(` and `)` not `[]` 
    $interval = $this->session->userdata('post'); 

    return $interval; 
} 



public function getInt() 
{ 
    $interval = $this->updateInt(); 

    // Test 
    echo $interval['my_interval']; 

    // print $interval and do some stuff !! 
} 
+0

非常にうまくいきます。 –

+0

@SoptareanuAlexもし動作すれば答えを受け取らないようにしてください。 – user4419336

関連する問題