Leaf v1.4.2 has thrown in a few more stuff since our session support in v1.3. We have a few more methods and better usability to offer. Let's check it out.
To include the Session object in a route, use this:
Sessionclass, and we pass it into the route with
In v1.4.2, starting a new session will automatically generate a session id for you.
Starting a new session
Starting a new session with leaf is actually very simple😅..
set() simply adds another key value pair to the native $_SESSION array. It takes in 2 parameters: The array key and it's pair.
remove() simply deletes a session variable. It takes in 1 parameter: the key of the variable to delete.
reset() simply re-initialises a session.
id() sets and/or returns the current session id. It takes in an optional parameter: the ID to overwrite the session id.
regenerate() simply generates a new session id. It takes in 1 parameter, whether to delete all session data or not(boolean)
destroy() ends a session and deletes all it's data
getParam is a method built for APIs, but can be used in a normal web app/website. It takes in one parameter: the name of the param passed into the app through the session
It works just like how
getBody() returns the key => value pairs of all the session data including any CSRF data
Next StepsSimple Routing