There are many ways to store sessions in Phalcon.
$di->set('session', function () {
$session = new SessionAdapter();
$session->start();
return $session;
});
or with more configuration options:
$di->set('session', function() {
$session = new \Phalcon\Session\Adapter\Files(['lifetime' => 10, 'cookie_lifetime' => 10]);
$session->start();
return $session;
}, true);
You need to install https://github.com/phalcon/incubator
first
use Phalcon\Db\Adapter\Pdo\Mysql;
use Phalcon\Session\Adapter\Database;
...
$di->set('session', function() {
// Create a connection
$connection = new Mysql([
'host' => 'localhost',
'username' => 'root',
'password' => 'secret',
'dbname' => 'test'
]);
$session = new Database([
'db' => $connection,
'table' => 'session_data'
]);
$session->start();
return $session;
});
https://docs.phalconphp.com/en/3.0.0/api/Phalcon_Session_Adapter_Files.html https://docs.phalconphp.com/en/latest/api/Phalcon_Session_Adapter.html