Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Session problem

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

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

Page: 1
Go to End
Author Topic: 2279 Views
  • Jean-Phi
    Avatar
    Community Member
    12 Posts

    Session problem Link to this post

    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

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: Session problem Link to this post

    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

  • Jean-Phi
    Avatar
    Community Member
    12 Posts

    Re: Session problem Link to this post

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

  • Sam
    Avatar
    Administrator
    679 Posts

    Re: Session problem Link to this post

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

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: Session problem Link to this post

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

    2279 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.