[eluser]draconus[/eluser]
I have been working with sessions for a little while now, and all works as it should. the only issue I am experiencing is that every time I load a view, I have to set the session variables to an array in order to pass them to the view. Is there a good way to store the variables to a config file so that I don't have to call it with each view?
Here is what I mean:
Code:
$data['firstName'] = $this->session->userdata('firstName');
$this->load->view('member/profile', $data);
It would make better sense, and would probably be the way I want, to pass the session array right into the view, kind of like this:
Code:
$this->load->view('member/profile', $session);
And just set $session = $this->session->userdata(); or something like that in the constructor class, and defaulting it to empty if no session is present.
But if that is a no go, perhaps I can create a config file that would look something like the following:
Code:
$config = array('session' =>
array(
'firstName' => $this->session->userdata('firstName'),
'lastName' => $this->session->userdata('lastName'),
);
But what would I name the config file for it to access the session variables correctly so I can get this information back to the controller.
In the mean time, I am recreating an array every time I load a view, which is definitely far from DRY.
I have heard recommendations that this can be done within the constructor class, but it complains with an error any time you try to create such an array because it can't call anything from session.
Any hints on how you guys tackle this in your projects would be greatly appreciated.