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.

General Questions /

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

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

Member-specific session data


Go to End


5 Posts   1967 Views

Avatar
pingu

Community Member, 75 Posts

27 May 2010 at 12:25pm

Edited: 27/05/2010 12:26pm

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

Forum Moderator, 5523 Posts

27 May 2010 at 12:53pm

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

Community Member, 75 Posts

27 May 2010 at 1:10pm

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

Forum Moderator, 5523 Posts

27 May 2010 at 2:10pm

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

Community Member, 75 Posts

27 May 2010 at 2:11pm

Awesome - thanks!!