Response

Learn how to return a response that forces a redirect

Redirect

The \BitFrame\Message\ResponseTrait provides a handy withRedirect() method to return an HTTP response with redirect. The signature for the method is as follows:

$response->withRedirect(
    // the redirect destination
    $url,

    // the redirect http status code
    // (if null and response status is 200 so far, then
    // a status 302 is set by default)
    ?int $status = null
): ResponseInterface;

Consider, for example, the usage shown below:

$app->get("/about", function ($request, $response, $next) {
   // issue redirect with status 307
   return $response->withRedirect(
       'https://www.designcise.com', 307
   );
});

An HTTP status code other than 3xx will result in a \BitFrame\Exception\HttpException.

This is a non-PSR standards based method, and is only available on class objects that use \BitFrame\Message\ResponseTrait. Default response objects created in BitFrame have this trait included automatically. The use of this helper method is strictly optional as it's merely meant as a shortcut to what you can just as easily accomplish without using it.

Comments

Let us know if you have something to say or add