Reputation: 9
Hi i have this new type of problem it is that my codeignitor sessions not work in other functions in controller
for example my login3 function
\\Data is coming from here fine
foreach($query as $row)
{
$name = $row->name;
$id = $row->id;
$dmail = $row->email;
}
if(isset($dmail))
{
$arr = array();
$arr['name'] = $name;
$arr['id'] = $id;
$arr['email'] = $email;
$this->session->set_userdata("facebooker",$arr);
$this->load->model('Gift');
$this->load->library('session');
$der = $this->session->userdata("facebooker");
$arrr = array();
$arrr['unamer'] = $der['name'];
$arrr['ids'] = $der['id'];
$arrr['email'] = $der['email'];
//After loading the views all data shows fine
$this->load->view("gifttoday/header",$arrr);
$this->load->view("gifttoday/welcome",$arrr);
}
But when i call the same session in this function but in same controller it shows no data
function profileselect()
{
$this->load->model('Gift');
$var =array();
$this->load->library('session');
// Here i call this session but no data
$mer = $this->session->userdata("facebooker");
// When i print all the values of $mer it shows empty array
var_dump($mer);
/**
$this->load->view("gifttoday/header",$arrr);
$this->load->view("gifttoday/profilev",$arrr);
**/
}
I have searched this problem and my people are having this problem with codeignitor sessions but non of the fixes worked for me can any body help me with this.
Upvotes: 1
Views: 2140
Reputation: 37701
You're calling the library after setting the session data which probably overwrites it (in case you already had the session library loaded in the first place):
So this:
$this->session->set_userdata("facebooker",$arr);
$this->load->model('Gift');
$this->load->library('session');
Should be this:
$this->load->library('session');
$this->session->set_userdata("facebooker",$arr);
$this->load->model('Gift');
But, if you intend to use the session library in several places in your app, it's a better idea to autoload it...
Edit this line in file application/config/autoload.php
$autoload['libraries'] = array('session',...);
and then just avoid loading it manually when needed.
Upvotes: 1
Reputation: 1391
Better is to load session Library in constructor
public function __construct()
{
$this->load->library('session');
}
Or enable session Library in config.php
Upvotes: 1