Welcome Guest, Not a member yet? Register   Sign In
Using session variables in models
#1

[eluser]swissbastian[/eluser]
Hi there

I'm just trying to use self setted session variables in a model. Calling them with $this->session->userdata('item') as I do it in my controller or view files does not work in a model.

Any advice how to do that?
#2

[eluser]Randy Casburn[/eluser]
Probably a scoping issue. Please make sure you understand what $this is pointing to.

Perhaps the object does not have a session member? You need access to the CI super object.

Randy
#3

[eluser]swissbastian[/eluser]
I'm unsure about these things: super object, session member…

You have an example?
#4

[eluser]Randy Casburn[/eluser]
Put the basic parts of your model here in [ code ] tags and let me take a look...
#5

[eluser]johnwbaxter[/eluser]
You can do the following if you want:

Controller:
Code:
function Jeff()

{
    $harry = $this->session->userdata(’item’);
    $this->load-model('Bert');
    $this->Bert->ModelFunctionName($harry);

}
So from above you can pass the $harry variable to the model function you're calling by putting it in the brackets.

model:
Code:
function ModelFunctionName($harry)
{

    $this->db->select($harry);
    $query = $this->db->get();

}
Then in the model you tell it to expect a variable ($harry) when it's run and so the model can use this variable.

This is a very simplistic example but it should show you what you can do to pass data around.




Theme © iAndrew 2016 - Forum software by © MyBB