I'm new at using Play Framework 2.0 (I am using Scala) and have a question about sessions.
I come from a Ruby on Rails background, so I tend to think of everything that I learn in Play Framework with respect to Ruby on Rails.
With that in mind, is there any way for me to call stuff stored in the Session while I am in the view?
If I have "hello" -> "world" stored in the Session, I want to be able to do something like @session.get("hello") and be able to use "world" in the view. Is this possible?
The other option I see is to store the value in a variable in the controller, and pass that along to the view by doing something like OK( var ), but that way seems kind of clunky especially if I start using more variables.
Thanks!
Sessions in Play store in cookies and are really just for cross-request data. If that is what you want then you can use @session.get("hello")
but what you might actually be after is a way to pass stuff from controllers to templates without having to specify them as parameters. In that case, see the very detailed answer to that question here:
https://stackoverflow.com/a/9632085/77409
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With