Slim V3 SESSION Middleware Class not Found


#1

Probably a quick fix but I’m trying to get my head around using Slim PHP middleware for my applicaton but more specifically, the SESSION middleware provided by bryanjhv.

I’m using 000webhost to host my API and database however I cannot seem to get the middleware to work.

There error that is occuring which suggests it cannot find the middleware classes/files. Here:

enter image description here

My API code:

$app = new \Slim\App;
$app->add(new \Slim\Middleware\Session([
  'name' => 'dummy_session',
  'autorefresh' => true,
  'lifetime' => '1 hour'
]));

As i said, I suspect it has something to do with my file structure.

enter image description here

If anyone has any ideas on this, please let me know.

Many thanks :slight_smile:


#2

How did you install bryanjhv/slim-session?


#3

1: I ran the cmd and typed this command: composer require bryanjhv/slim-session:~3.0
2. I uploaded the outputted composer.json and composer.lock files into the root of my project (replacing old files)
3. Inserted the API code as shown above
4. Uploaded the /Silm/Middleware/Session.php and /SlimSession/Helper.php files as shown above

I’ve tried uploading the vendor folder too. Still not working.

Thanks for the quick reply tflight :slight_smile:


#4

That doesn’t sound right. It could be for your environment, if it has some sort of special requirement I’m unaware of.

You should open your terminal and cd into your /storage/ssd2/263/551263 directory. From there, run the composer require command. That will install the session package into your vendor folder. You shouldn’t need the Slim directory under your src directory.


#5

Ahhh ok now were getting somewhere. The middleware is found and i can now implement it.

Howevere I am new and not sure how it really works. Essetnaily i just want to use PHP native sessions throughout my API.

Now the problem is that everytime an API call is made to the database, a session file is created.

jJeEd

Any ideas on this. Almost there!!