Reputation: 159
i post value through ajax in codeigniter controller function , and trying to store value in session like this
function abc{
$studio = $_POST['studio'];
$trnr_type = $_POST['trnrtyp'];
$this->session->set_userdata('studio',$studio),$this->session->set_userdata('trnr_type',$trnr_type)
}
and use this value
$st = $this->session->userdata('studio');
$tr = $this->session->userdata('trnr_type');
but not getting value in session variable.
Upvotes: 0
Views: 1605
Reputation:
This is what the user guide says to do
http://www.codeigniter.com/user_guide/libraries/sessions.html#adding-session-data
public function abc() {
$sessiondata = array(
'studio' => $this->input->post('studio'),
'trnrtyp' => $this->input->post('trnrtyp')
);
$this->session->set_userdata($sessiondata);
}
Make sure you have set your session save path on config.php don't leave it null
Upvotes: 0
Reputation: 133
1. Load session library into your controller:
$this->load->library('session');
2. Get your data:
$studio = $this->input->post('studio');
$trnrtyp = $this->input->post('trnrtyp');
3. Set session data:
$this->session->set_userdata('studio', $studio);
$this->session->set_userdata('trnrtyp ', $trnrtyp );
4. Get session data:
$st = $this->session->userdata('studio');
$tr = $this->session->userdata('trnr_type');
Upvotes: 0
Reputation: 1
Before call abc function load sesion library
function abc() {
$session = array('studio'=>$_POST['studio'],'trnr_type'=>$_POST['trnrtyp']);
$this->session->set_userdata($session);
}
Upvotes: 0
Reputation: 319
//set user data
$this->session->set_userdata('username',$username);
//get user data
if($this->session->has_userdata('username'))
{
$userid = $this->session->userdata('username');
}
Hope this is what u are looking for
Upvotes: 0
Reputation: 116
Load the session library in your controller by the following
$this->load->library('session');
then you have to post the data to the codeigniter controller then at the controller you have to do the following
$sess_array = array(
'studio' => $this->input->post('studio'),
'trnr_type' => $this->input->post('trnrtyp'),
);
$this->session->set_userdata('studio',$sess_array);
Upvotes: 2