plainblack.com
Username Password
search
Bookmark and Share
Subscribe

Session

According to the API docs, the Session "package is the heart and lifeblood of WebGUI; it is the glue that holds WebGUI together. When you create a session object, you'll immediately have access to all sorts of other objects. By passing the session object around in code you'll have access to the default database connection, error handler, user and more without having to create it each time. This lends much speed to WebGUI."

"NOTE: It is important to distinguish the difference between a WebGUI session and a user session. A user session is just part of a WebGUI session. A WebGUI session is all of the basic data the WebGUI needs to operate."

 

Session Scratch variables

Part of the session, is the scratch. A scratch variable can store some (max 16000 characters) information on a per-session basis. Very much like a cookie, but more flexible and easier to use: it can be set and deleted with a url and retrieved as a template variable.

Setting a scratch variable

A scratch variable can be set by appending this to the url:

?op=setScratch&scratchName=where&scratchValue=back

When the user clicks this link, a scratch variable with the name www_where will be added to his session. The name is prefixed by "www_" to prevent overriding programmatically set scratch variables. The scratch variable www_where will have the value "back". This can be done for a logged-in user, as well as for a visitor. Different visitors have different sessions, and the scratch variable is tied to the session.

 

Retrieving the scratch variable value

The scratch variabele can be retrieved as a template variable like so:

<tmpl_var session.scratch.www_where>

And can of course - like all template variables - also be used in a conditional form like so:

<tmpl_if session.scratch.www_where>

 

Deleting a scratch variable

If a scratch variable is used in a conditional form, it can be handy to be able to delete the variable. This can be done by appending to the url:

?op=deleteScratch&scratchName=where

This will delete the scratch variable that could be retrieved as session.scratch.www_where.

 

Example

To try this, you could put this into a snippet:

<a href="/^Page(url);?op=setScratch&scratchName=where&scratchValue=back">Scratch
me</a><br />
<a href="/^Page(url);?op=deleteScratch&scratchName=where">Scratch
me not</a><br />
From www_scratch: <tmpl_var session.scratch.www_where><br />

Don't forget to set the cache-timeout of the snippet to zero and make sure process as template is set to yes.

 

Discussions

Earlier discussions about using the session scratch:

  • http://www.webgui.org/web_design_templates_and_themes/scratch-variables
  • http://www.webgui.org/etcetera/sessionstow

Keywords:

Search | Most Popular | Recent Changes | Wiki Home
© 2018 Plain Black Corporation | All Rights Reserved