Session configuration is in /etc/config.yml.

    handler: native
    expire_time: 15

By default, Windwalker use php native to handler session data. The expire time unit is minute.

Get Session Object

$session = \Windwalker\Ioc::getSession();

// OR

$session = $container->get('system.session');

Store And Get Session Data

$session->set('flower', 'sakura');

$data = $session->get('flower', 'default');

$session->exists('animal'); // bool

Restart Session


Session Bags

Session bag is a data storage to store data, we can add many bags to Session object and access them.

Use Default Bag

Get Default Bag


Get data from default bag.


// OR

Use Custom Bags

use Windwalker\Session\Bag\SessionBag;

$session->setBag('mybag', new SessionBag);

// Get data
$myBag = $session->getBag('mybag');

$myBag->set('foo', 'bar');
$myBag->get('foo', 'default');

We can use Namespace to get data from bags

// Get form default bag
$session->get('foo', 'default', 'mybag');

// Get from mybag
$session->get('foo', 'default', 'mybag');

// Set to mybag
$session->set('foo', 'bar', 'mybag');

Flash Data

Flash bag is a data temporary storage, if we take data out, the bag will be clear.

$session->addFlash('Save success.', 'info');
$session->addFlash('Login Fail.', 'error');

// Take all messages and clear
$allMessages = $session->getFlashes();

// Peek messages but don't clear


Windwalker Session provides many handlers to storage session, edit the config file.

    handler: memcached
    expire_time: 15

Use Database Handler

Before using database session, we have to add table schema information to session config.

    handler: database
    expire_time: 15
    table: sessions
    id_col: id
    data_col: data
    time_col: time

NOTE: Database Handler will be implemented in next release.

Available Handlers

  • apc
  • database
  • memcached
  • native
  • xcache

If you found a typo or error, please help us improve this document.