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

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.


Could just use a session variable, in function A:

$this->session->set_userdata('my_id', $id);

Then in function B, C, D:


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