Creating a global user variable

I’m new to slim and trying to figure out the best way to create a global user variable. My first thought is to add it to the Container, but I can’t figure out how to inject $app into a route mapped to a class method. I saw somewhere that I can add Container $container to the constructor and the DI should do it automatically? Doesn’t seem to be working.

Plus, I need to access the variable in a middleware class I wrote to parse my Bearer header, and I can’t find any details on how to do that. I know I can pass $app into each ->add, but that’s a lot of repeated code, and I’m hoping I can avoid that.

I can show an example of my routes/middleware if it helps?

Hi! You should note that global variables are not a good thing.

Global Variables Are Bad.

Are you trying to handle a User Session in combination with a JSON Web Token?