Welcome Guest, Not a member yet? Register   Sign In
codeigniter session variable taking controller name instead of assigned variable
#1

[eluser]Unknown[/eluser]
I've come across a problem where my session variables are taking the name of the controller, instead of the variable assigned.. For example when calling the following URL

www.example.com/newprop/editprop/1

Code:
class Newprop extends CI_Controller {

public function __construct()
{
     parent::__construct();
     $this->load->library('session');
     //....... SNIP
}

public function index($returnvalue)
{
     $this->auth->is_logged_in();
     //........SNIP
}

public function editProp($propid)
{
     $this->session->set_userdata(array("propid"=>$propid)); //problem here
     //.......SNIP
     $this->index($returnvalue);
}

I would expect the session info in the database to be
Code:
s:8:"propid";i:1:1;
Instead it is
Code:
s:8:"propid";s:7:"newprop";
If I echo $propid, the value is indeed 1 before it goes into the session.

If I immediately echo the session data after setting it...

Code:
$this->session->set_userdata(array("propid"=>$propid));
echo $this->session->userdata("propid");

I get "1" even though this is not stored in the DB, but if I try to echo the session data from another controller, I get the string "newprop"

I'm storing session info in the database. If I forgot any other useful information please let me know.


EDIT: If I remove the $this->index($returnvalue); from the editProp() method, the session is set correctly... Not sure if I'm at fault or if CI is

EDIT 2:
Problem solved, I had an ajax request that was calling
www.example.com/newprop/editprop/newprop/......
which was setting the session variable a 2nd time. incorrectly.... now how do I delete this post...?





Theme © iAndrew 2016 - Forum software by © MyBB