On Jan 15, 7:10 am, LB22 <[email protected]> wrote:
> I've been trying to figure out how to handle sessions but have made
> little progress in the past couple of days. The manual, (and website)
> states that web2py handles sessions for you... I took this to mean
> that, beyond using session.connect(...) to initiate/create a session
> in the database, all you needed to do was store the session data in
> various session variables like session.example_data1="some user",
> session.exampledata2 ="same user's preferred colour scheme", and these
> session variables would get sent and retrieve as they were created and
> then referenced.
> This doesn't seem to be the case though (forgive my naivety). The
> sessions are definitely getting created in the DB, and I can see the
> cookies have the same unique_keys as the sessions created but, beyond
> this, I'm stuck. So would someone please explain briefly how to send
> and retrieve session data to/from the [mysql] database to utilise it
> within the application, and maybe provide a quick example?
Session variables don't get stored within the DB, but purely with the
session global variable.
You can set options in your Controllers, e.g.:
session.flash=T('Not Authorised!')
These then get interpreted in your views, e.g.:
{{if session.s3.debug:}}
I extend the session to read options from the database by having this
in my model:
def shn_sessions(f):
" Extend session to support extra variables "
session.s3.debug=db().select(db.s3_setting.debug)[0].debug
return f()
response._caller=lambda f: shn_sessions(f)
Hope this helps :)
F
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---