akrabat / rka-slim-session-middleware
Simple session middleware for Slim Framework
Installs: 209 376
Dependents: 7
Suggesters: 0
Security: 0
Stars: 43
Watchers: 6
Forks: 13
Open Issues: 7
Requires
- php: >=7.4
- psr/http-server-middleware: ^1.0
Requires (Dev)
- phpunit/phpunit: ^9.5
- slim/psr7: ^1.5
README
Middleware for Slim Framework that starts a session. Also provides a useful Session
class.
Installation
composer require "akrabat/rka-slim-session-middleware"
Usage
Add middleware as usual:
$app->add(new \RKA\SessionMiddleware(['name' => 'MySessionName']));
RKA\Session
You can use \RKA\Session
to access session variables. The main thing that this gives you is defaults and an OO interface:
$app->get('/', function ($request, $response) {
$session = new \RKA\Session();
// Get session variable:
$foo = $session->get('foo', 'some-default');
$bar = $session->bar;
// Set session variable:
$session->foo = 'this';
$session->set('bar', 'that');
return $response;
});
if you need to destroy the session, you can do:
\RKA\Session::destroy();