Closed garek007 closed 1 year ago
odan/session
Thanks @odan . I'm struggling a bit with how to use this in Slim 4 and also where to use it. I did see you have some documentation about that for version 5 (which I installed) and I've read in other questions I should use it as a middleware, but I'm also a bit confused by that concept. Mainly, I want it to be clean. Currently. I have my index.php file and it looks like this.
<?php
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;
use Slim\Views\Twig;
use Slim\Views\TwigMiddleware;
require __DIR__ . '/../vendor/autoload.php';
$app = AppFactory::create();
//session stuff here? Using slim middleware?
// Create Twig
$twig = Twig::create(__DIR__.'/views', ['cache' => false]);
// Add Twig-View Middleware
$app->add(TwigMiddleware::create($app, $twig));
$app->get('/loadit/{externalkey}', \App\Action\LoadDataExtension::class);
$app->get('/', function (Request $request, Response $response, $args) {
//$response->getBody()->write("Hello world!");
//echo $_SERVER['REQUEST_URI'];
//return $app['twig']->render('index.twig');
$view = Twig::fromRequest($request);
return $view->render($response, 'index.twig');
});
$app->run();
I plan to have most of my routes as you see there for /loadit/{externalkey} where the code is in a controller. I figured I can include this in my controller
use Odan\Session\PhpSession;
And use sessions in each controller, but not sure if that's the "best" way.
I could not answer this question because I was on vacation. Have you solved this issue?
I did, thanks Odan
You list 4 session packages. Is one preferred over the others?