Reputation: 113
I want to send data between one middleware to other. As one middleware passes, I want to add some JSON response and pass to next middleware. What can be the best possible way to do it in Slim 3.
For example:
$app->post('/main_route/','reset_password')->add('middleware2')->add('middleware1');
How can I send some JSON data from middleware1 to middleware2 and then to main route?
Upvotes: 3
Views: 870
Reputation: 8938
The docs explain how to do this:
In the first middleware you can do:
$request = $request->withAttribute('foo', 'bar');
In the second middleware ...
$foo = $request->getAttribute('foo');
Upvotes: 1