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.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Member-specific session data


Reply

5 Posts   1553 Views

Avatar
pingu

27 May 2010 at 12:25pm (Last edited: 27 May 2010 12:26pm), Community Member, 75 Posts

I'm currently using silverstripe's built in member management functions to log users in and out so that they can see various areas of front-end templates available to logged-in users only.

I also need to store additional data for logged in members in a session (wishlist/cart items). Is there a member-specific session that I can use/add to that will be automatically destroyed on logout?

Alternatively, what other ways can I do this?

Avatar
Willr

27 May 2010 at 12:53pm Forum Moderator, 5511 Posts

You can use the Session class to store values tied to a session. Another less secure / robust way is using cookies.

Session::set('MyValue', 2);
Session::get('MyValue');

http://api.silverstripe.org/2.4/sapphire/control/Session.html
http://api.silverstripe.org/2.4/sapphire/misc/Cookie.html

Avatar
pingu

27 May 2010 at 1:10pm Community Member, 75 Posts

Thanks Willr.
Could you give me a specific example of how I could tie a value in with the member session -- sorry, haven't worked much with sessions in SS.

Avatar
Willr

27 May 2010 at 2:10pm Forum Moderator, 5511 Posts

Ask and you shall receive! I've done up a documentation page explaining it and examples on how to use it.

http://doc.silverstripe.org/sessions

Avatar
pingu

27 May 2010 at 2:11pm Community Member, 75 Posts

Awesome - thanks!!