[eluser]Unknown[/eluser]
Hi
I've have this problem with the session and i can't wrap my head around it.
Each time I grab data from a link and put it in a session, the session data gets lost when i return to the controller using a link or a form from within the View.
This is the case:
i'm trying to store an id number in a database session. I pass the data through a link like this:
/admin/project/id/3
I grab the number from the link with $this->uri->segment(4) or just pass i through the function as a parameter.
function id($project_id)
{
$newdata = array(
'project_group_id' => $project_id
);
$this->session->set_userdata($newdata);
$this->overview();
}
function overview($param = array())
{
if(is_array($param))
{
foreach($param AS $key=>$value)
{
$data[$key] = $value;
}
}
$data['project_group_data'] = $this->project_model->get_all_groups();
$data['project_data'] = $this->project_model->get_project_data_by_id($this->project_group_id);
$data['load_page'] = 'admin/project_view';
$data['page_title'] = 'Projects';
$data['username'] = $this->session->userdata('username');
$this->load->view('admin/include/template', $data);
}
In the View, the session data is still traceable by var_dump() and with print_r(). But when i look in the database session, the data has changed to 'resources'.
var_dump($this->session->userdata):
array(7) {
["session_id"]=>
string(32) "582048e72c8a871d49e7fded35903229"
["ip_address"]=>
string(7) "0.0.0.0"
["user_agent"]=>
string(50) "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2; "
["last_activity"]=>
string(10) "1267801510"
["username"]=>
string(4) "Derk"
["is_logged_in"]=>
string(1) "1"
["project_group_id"]=>
string(1) "3"
}
print_r($this->session->userdata):
Array
(
[session_id] => 582048e72c8a871d49e7fded35903229
[ip_address] => 0.0.0.0
[user_agent] => Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2;
[last_activity] => 1267801510
[username] => Derk
[is_logged_in] => 1
[project_group_id] => 3
)
database session:
a:3:{s:8:"username";s:4:"Derk";s:12:"is_logged_in";s:1:"1";
s:16:"project_group_id";s:9:"resources";}
When i go back to the controller using a link or form, all the project_group_data is set to 'resources'.
var_dump($this->session->userdata):
array(7) {
["session_id"]=>
string(32) "9bbdb190935837ef8cf631c7b35eed28"
["ip_address"]=>
string(7) "0.0.0.0"
["user_agent"]=>
string(50) "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2; "
["last_activity"]=>
int(1267801943)
["username"]=>
string(4) "Derk"
["is_logged_in"]=>
string(1) "1"
["project_group_id"]=>
string(9) "resources"
}
print_r($this->session->userdata):
Array
(
[session_id] => 582048e72c8a871d49e7fded35903229
[ip_address] => 0.0.0.0
[user_agent] => Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_2;
[last_activity] => 1267801510
[username] => Derk
[is_logged_in] => 1
[project_group_id] => resources
)
When i put some hardcoded data in the session like 'test' the data stays untouched.
So it seems dat the problem occures with dynamic data passes through from controller->controller & controller->view->controller.
Any suggestions, ideas.
Cheers,
Derk