Skip to content

Session

florin-botea edited this page Jan 21, 2022 · 1 revision

Working with Session

use Aweb\Nexus\Session;

Any non bulk accessor or mutator method can be used with dot notation key for nested data (Session::get('foo.bar')) Session class is actually manipulating with the original OpenCart registry Session object.

Session::has()

The Session::has method checks if an attribute is defined on session, eq OpenCart array_key_exists($session->data, $key)

Session::get()

The Session::get method returns an attribute, eq OpenCart $session->data[$key]

Session::set()

The Session::set method sets an attribute on session, eq OpenCart $session->data[$key] = $value

Session::put()

The Session::put method sets an attribute on session, eq OpenCart $session->data[$key] = $value

Session::pull()

The Session::pull method retrieve an attribute then remove it from session

Session::increment()

The Session::increment method if your session data contains an integer you wish to increment or decrement, returns result. if no session key is defined, it initiate it as 0 then apply the operation.

Session::decrement()

The Session::decrement method if your session data contains an integer you wish to increment or decrement, returns result. if no session key is defined, it initiate it as 0 then apply the operation.

Session::all()

The Session::all method returns attributes.

Session::forget()

The Session::forget method Removes an attribute.

Session::flush()

The Session::flush method clears all attributes. if $names are given, clear only them

Session::getId()

The Session::getId method get session id

Session::getName()

The Session::getName method get session name

Session::getFlashBag()

The Session::getFlashBag method returns Flash bag

Session::flash()

The Session::flash method To persist your flash data only for the current request. Sometimes you may wish to store items in the session for the next request. You may do so using the flash method. Data stored in the session using this method will be available immediately and during the subsequent HTTP request. After the subsequent HTTP request, the flashed data will be deleted. Flash data is primarily useful for short-lived status messages:

$request->session()->flash('status', 'Task was successful!');

Session::reflash()

The Session::reflash If you need to persist your flash data for several requests, you may use the reflash method, which will keep all of the flash data for an additional request.

$request->session()->reflash();

Session::keep()

The Session::keep method if you only need to keep specific flash data (move them from _flash to permanent)