You are viewing the website for BitFrame v1. BitFrame v2.0 was released on 11-May-2020 — new documentation and website will be available soon!


Learn how to return a response that forces a 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:

    // the redirect destination

    // 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(
       '', 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.


Let us know if you have something to say or add