Welcome Guest, Not a member yet? Register   Sign In
retaining a value in a controller variable
#1

[eluser]ssachan[/eluser]
Hello Developers

I am stuck at a design issue.

I have a controller class which has a variable
var id
It is set in a function A and is required in all the
functions in this controller (lets say B, C and D)

Now functions B,C,D and called for my views which leads to
reinitialization of the controller and loss of id which was
set in function A.

The only solution I see is to pass the id to my views and then
again to all the functions B, C and D whenever they are called.

But I guess is this is not the best way to do it. Is there any way
I can set the value of id and retain it till its changed the next time.


Thanks
#2

[eluser]bhogg[/eluser]
Could just use a session variable, in function A:

Code:
$this->load->library('session');
$this->session->set_userdata('my_id', $id);

Then in function B, C, D:

Code:
$this->load->library('session');
$this->session->userdata('my_id');

As a side note the id should probably be validated in function A otherwise a user could just change the URL and set whatever ID they would like.




Theme © iAndrew 2016 - Forum software by © MyBB