My project has several views which draw values out of the session->userdata array.
the whole project works flawlessly on my development machine, but when I copied the project up to a server, I find that $this->session->userdata is null.
This is the code which inserts some values into the session->userdata array:
It is called in the Controller.
$sessionArray = array(
'web_id' => $id,
'paperId' => $paperId,
'prelimId' => $prelimId,
'intakeId' => $intakeId,
'finalId' => $finalId,
);
$this->session->set_userdata($sessionArray);
In the view file I call
var_dump($this->session->userdata);
The value returned is null. As I mentioned before, the array is NOT null on my development computer (running WAMP). Does anyone know why?
In order to retrieve all session data as an ASSOC array, you could use the
all_userdata()method. (Take a look at CodeIgniter user guide),You can write that within your Controller and send the returned value to the view, as follows:
Note: Using the session library directly inside the views may cause unexpected problems. Try managing your sessions in the Controller instead of the View.