This boilerplate Slim repo seems to have some errors

Hi!

Im trying to finish up this slim boilerplate repo. But for some reasons I’m getting two (2) errors that i can’t really figure out how to solve. Oddly enough it doesn’t effect MAMP more then giving two lines of errors. But ofc when running php -S 0.0.0.0:8888t public public/index.php I get error feedback in browser.

[01-Jun-2016 22:01:33 Europe/Stockholm] PHP Notice:  Undefined index: user in /htdocs/slim3/app/Auth/Auth.php on line 11
[01-Jun-2016 22:01:33 Europe/Stockholm] PHP Notice:  Undefined index: errors in /htdocs/slim3/app/Middleware/ValidationErrorsMiddleware.php on line 9

The two lines are can be reviewed here, Auth.php and ValidationErrorsMiddleware.php

In my efforts to troubleshoot, I think dependencies.php dependencies.php view container is the malfunction function.

Just a guess here, but the errors reported would seem to indicate that you have a problem with your $_SESSION (or the data that you put (or rather, don’t put)) into it. Are you sure your $_SESSION is properly initialized and handled?

But yes, accessing those $_SESSION variables should probably be placed in a isset() check.

session is initialized on this line. And i can var_dump($_SESSION) at bottom of dependencies.php with results.

Something with middleware maybe?

This means that user and errors are not set on $_SESSION.

You should check them first:

if(isset($_SESSION['user'])) ...

if(isset($_SESSION['errors'])) ...

or something like:

$user =  isset($_SESSION['user']) ? $_SESSION['user'] : NULL;

$errors =  isset($_SESSION['errors']) ? $_SESSION['errors'] : NULL;
1 Like

I went with that solution, checking if they are set/empty or not.