Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

Session problem


Go to End


5 Posts   3225 Views

Avatar
Jean-Phi

Community Member, 12 Posts

2 July 2008 at 6:54pm

Hi, I'm trying to put an object into $_SESSION by this way :

$current_seller=DataObject::get_by_id('Seller', $user_id);
Session::set('user', $current_seller);

when in other action, I want to get my seller back by this way :

$this->seller=Session::get('user');

the $this->seller object is incomplete, when I do a print_r($this->seller), I've got "__PHP_Incomplete_Class Object".

I think that's because session_start() is called before the model's classes definition...

Sorry for my english :)

Avatar
Sean

Forum Moderator, 922 Posts

2 July 2008 at 7:18pm

Edited: 02/07/2008 7:21pm

AFAIK, this is because session doesn't put the object in correctly unless you serialize it, and then unserialize it back.

e.g.


$obj = DataObject::get_one('Page');

// Set the object in session
Session::set('MyPage', serialize($obj));

// Get it back again
$returnObj = unserialize(Session::get('MyPage'));

Cheers,
Sean

Avatar
Jean-Phi

Community Member, 12 Posts

2 July 2008 at 7:36pm

ok thanks, It should be interesting that Session::set(....) and Session::get(...) automatically serialize and unserialize objects.

Avatar
Sam

Administrator, 690 Posts

7 July 2008 at 3:07pm

We tend to avoid putting objects into session. Just put $current_seller->ID in the session.

Avatar
Sean

Forum Moderator, 922 Posts

7 July 2008 at 3:08pm

This is true. Isn't there some sort of character length maximum for session?