Session in CI4

Storing Data in Session

Use the session() helper function or the Config\Services::session() method to access the session instance.

Storing Grouped Session Data

Use the session()->set() method to store an array under a key.

Retrieving Grouped Session Data

To retrieve all data under the logged_in key:

 

Updating Grouped Session Data

To update a specific value within the grouped session data:

 

Removing Grouped Session Data

To remove all data under the logged_in key:

Checking if Grouped Data Exists

To check if the logged_in key exists in the session:

 

Storing Data Under Multiple Groups

If you need multiple grouped sessions, you can store different arrays under different keys:

To retrieve them individually:

 

Leave a Reply

Your email address will not be published. Required fields are marked *