Jump to content

use $session in functions?


helmut2509
 Share

Recommended Posts

Hello,

I want to use the $session variable in functions, inside a template. According to the API this variable is available only in templates.

But all values of the $session variable get lost, even when I use 'global $session'.

is there any workaround for this problem?

 

Link to comment
Share on other sites

1 hour ago, adrian said:

Like any other ProcessWire variable, the easiest way to access them inside a function is: 


wire('session')

 

In the function I wrote 

wire('session')->set('number', '12345');

and outside the function I tried :

echo $session->number

...but this variable was empty....

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...