Module Session Variable

SoftDesigns
SoftDesigns
@softdesigns
7 years ago
242 posts
What is the correct way a custom module should set global session variables that all other modules can access?
--
Raw PHP would be: $_SESSION["favcolor"] = "green";
--
Are there equivalent JR platform functions to handle session?
updated by @softdesigns: 07/01/17 08:35:18PM
michael
@michael
7 years ago
7,714 posts
That's fine.

It depends on what you're trying to do as to what its better, sometimes:
jrCore_set_flag()
jrCore_get_flag()

Will be the correct thing to use, sometimes
jrCore_set_temp_value()
jrCore_get_temp_value()

Sometimes you'll want to set values to the global $_conf variable if its a more constantly there thing.

Sometimes
jrCore_set_cookie()
jrCore_get_cookie()

All depends on the situation.
SoftDesigns
SoftDesigns
@softdesigns
7 years ago
242 posts
Thanks for the various options above.
Very helpful to have some guidance when searching thru JR source.
Will need time to study...
--
Great Support
updated by @softdesigns: 03/31/17 06:59:01PM
michael
@michael
7 years ago
7,714 posts
In my mind, jrCore_set_flag() jrCore_get_flag() are for passing a value across locations during a single phase. Like if I was in an event listener in my module, but needed to take action on that later on in the cycle of things for whatever reason, perhaps check the state of things at one listened for event, then do something at another event listener.

jrCore_set_temp_value() jrCore_get_temp_value() are useful for passing things across ajax boundaries. Like the search parameters that came in to the main page, then save them to a set_temp_value to preserve them for the pagination that happens via ajax. It means you dont need to pass them in with every ajax request, just see if they are set.

and set_cookie is useful for preserving the user chosen last state of things, like if you wanted to always use the same size of image. let the user save the size of image they are interested in and re-select that next time for them by default.

Tags