Commit aee1759e authored by Amos Latteier's avatar Amos Latteier

Removed API programming docs. This is now covered in the Zope Book.

parent 1387bfb5
Session API Programming
Overview
Sessions allow you to maintain state associated with anonymous
users between requests. A session is a temporary "scratch" area
in which you can store information related to a site visitor.
A "session" ends when a visitor who begins a session neglects to
revisit your site in some number of minutes.
Usage
Developers will usually interact with the SESSION object stored
in REQUEST in order to perform session-related tasks.
More infrequently, developers will interact directly with
Browser Id Manager and Session Data Manager objects.
Common Programming
In order to manipulate session data, you interact with the
REQUEST.SESSION object.
For example, in DTML you might::
<dtml-with SESSION mapping>
<dtml-var cart missing="You have no cart">
</dtml-with>
or even more simply::
<dtml-var SESSION>
This would print the cart object in the session, or the entire SESSION
object. You could set an object in the session similarly to how you
set it in the REQUEST::
<dtml-call expr="SESSION.set('cart','this is really more of a wagon')">
You may change the name of the SESSION object in the management screens
for the session data object. You can do more complex operations on
SESSION data with python scripts, e.g.::
session = context.REQUEST.SESSION
cart = session.get('cart',()) # Get our cart or an empty list
cart.append(('my line item',100.00))
session['cart'] = cart # force a save back to the session
Tips
Keep in mind that SESSION objects are a lot like dictionaries; if
you wish to iterate through them in the context of a dtml-in expression,
you should use something like::
<dtml-in expr="SESSION.items()">
<dtml-var sequence-key>: <dtml-var sequence-item>
</dtml-in>
See Also
- "Session API":SessionInterfaces.py
- "Transient Object API":../../Transience/Help/TransienceInterfaces.py
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment