Welcome Guest, Not a member yet? Register   Sign In
Need a little more info using Filters 'After'

How do I use the $response (ResponseInterface) in the 'after' function for Filters? What are the properties that can be changed here? I need to modify the output. Also, is it possible to view controller variables in the 'after' function?

You are given the Response object that contains everything that will be sent to the client, and that's it. So - no controller variables. But you do have the status code, headers, cookies, and the generated HTML.

Take that info, play with it however you need, and return the response object. Your modified response is what is returned to the client at the point.

How do I do that in the 'after' function though?  How do I update the $response to edit the body?  Do I use a 'return' statement?  Call a function on the $response object?  I can't seem to find an example anywhere of how this would work for here:

public function after(RequestInterface $request, ResponseInterface $response)
  // how do I manipulate the $response var?
  // do I need to return the $response var or anything?

A couple of things to help out:

1. Docs for the Response object
2. the Response class itself

PHP Code:
public function after(RequestInterface $requestResponseInterface $response)
$body $response->getBody();
// Do stuff to body, set headers, whatever.
return $response->setBody($body);


Boom!  That's what I needed.  Thank you!

Theme © iAndrew 2016 - Forum software by © MyBB