The Slim Framework support forum has moved to This Tender forum is no longer maintained or monitored.

Slim 3 pass variables from middleware

Sam's Avatar


05 Nov, 2015 11:17 PM

In Slim 3, how do I pass internal variables from middleware to the route it was added to? Or create an app registry where I can set variables in middleware and access them from the get/post functions.

  1. 1 Posted by Rob Allen on 06 Nov, 2015 07:09 AM

    Rob Allen's Avatar

    The easiest way is to use the request's attributes:

    In middleware:

    $request = $request->withAttribute('foo', 'bar');

    In route callback:

    $foo = $request->getAttribute('foo');
  2. 2 Posted by Sam on 06 Nov, 2015 04:53 PM

    Sam's Avatar

    That is very easy. Thank you. I couldn't find that method anywhere in the docs. This info might be very helpful to add to the new docs for new people like myself. Perhaps in the Request Helpers section ( or the Middleware section (

    Again, thank you,

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac