Reference

Guide

$page->go()

Redirects to this page, wrapper for the go() helper

$page->go(array $options = [ ], int $code = 302)

Parameters

Name Type Default Description
$options array [ ]

Options for Kirby\Http\Uri to create URL parts

$code int 302

HTTP status code

Example

Redirect to another page

<?php
if ($page = page('blog')) {
  return $page->go();
}
?>

Redirection within the page

<?php
// /site/controllers/contact.php
return function ($kirby, $page) {
    if ($kirby->request()->is('POST')) {
        $sent = $kirby->email('contact', [
            'body' => 'Body',
        ])->isSent();

        if ($sent === true) {
            // Will redirect to /contact?status=success#contact-form
            return $page->go([
                'query' => [
                    'status'  => 'success',
                ],
                'fragment' => 'contact-form'
            ]);
        } else {
            // Will redirect to /contact?status=failed
            return $page->go([
                'query' => [
                    'status'  => 'failed',
                ]
            ]);
        }
    }
};
?>

Source code

kirby/src/Cms/Page.php#L489