New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Flash messages middleware failed. Session not found" when using default Slim test runner #27
Comments
To avoid $_SESSION, you can pass array Here is snippet of mine: // Flash messages
$container['flash'] = function ($c) {
$driver = \App\Factories\SessionFactory::create($c->get('settings')['session']['driver']);
return new Slim\Flash\Messages($driver);
};
// Session Factory
class SessionFactory
{
public static function create($driver)
{
switch ($driver) {
case 'array':
return [];
case 'native':
default:
return null;
}
}
}
// settings.php
'session' => [
'driver' => getenv('SESSION_DRIVER'),
], |
I've got that problem too! |
Start the session with |
@akrabat I have the same issue, session_start is called and also everything works on existing routes. For example I visit http://dev.vm/admin/login and everything works fine
Am I supposed to create a 404Controller or something to handle this? Or is this unexpected behavior? I register flash message like this in my ViewServiceProvider: // add \Slim\Flash messages
$engine->getEnvironment()->addGlobal('flash', $this->getContainer()->get('flash')); While typing, I think I figured out why this happens, but not how to solve it... That probably means that 404 routes have no session_start() called. Is that something flash messages should be aware of, as in if an exception was thrown or is that on developers end. |
Hi, I set up my application using the skeleton here: https://github.com/slimphp/Slim-Skeleton
Specifically I'm using this test runner to exercise controllers: https://github.com/slimphp/Slim-Skeleton/blob/master/tests/Functional/BaseTestCase.php
I defined a controller that says
$this->flash->addMessage('Error', 'Invalid phone number')
I get the following stack trace:
Not sure whether the error is in Slim's test runner or here, but it seems like this should work without blowing up.
It's also worth considering whether the default should be to fail silently instead of loudly.
The text was updated successfully, but these errors were encountered: