Redirects

The Redirect object has several methods for making a redirect. For example, you can redirect to a URL on the home page right way using the following code.

tr_redirect()->toURL(home_url('/sample-page/'))->now();

Make Redirect

$redirect = new \TypeRocket\Http\Redirect();

Or,

$redirect = tr_redirect();

To URL

To redirect to a URL use the toURL() method.

$redirect->toUrl( home_url('/blog') );

With Fields

To redirect with fields use the withFields() method. This is a great for when validation fails and you need to send the field data back to a form.

$redirect->withFields( ['field_name' => 'The field value'] );

To block fields from being returned use the second argument.

$redirect->withFields( ['field_name' => 'The field value'], ['field_name'] );

To Page

To redirect to an admin page created by TypeRocket as a Page use the toPage() method.

$resource = 'Seat';
$action = 'edit';
$item_id = 1;

$redirect->toPage($resource, $action, $item_id);

Redirect Now

To redirect right away use the now() method.

$redirect->now();