Redirects

In "$mv" object there are methods available to reload and redirect from one URL to another. All of them are using the "header()" function and ending with "exit()" function call.

Reload of the current page - reload()

This method reloads the current page and allows to add extra parameters to URL. The initial GET parameters will be removed. If no parameters were passed to the method, then the current page will be reloaded without old GET parameters.

//If the form is filled without errors, reload the current page and add GET parameter 
if($form -> isValid())
{
    ...

    $mv -> reload("?message-sent=1");
}

Redirect to other pages - redirect()

This method is used for redirecting to other page. If it is called without parameters, then redirect goes to the website root (to main page). It is possible to add both parts of links and GET parameters.

//If a user is not authorized, redirect to login page 
if(!$mv -> clients -> checkAuthorization())
    $mv -> redirect("login/");

//If registration form is filled correctly, then redirect 
//and if we possibly need to redirect user right to order submit 
if($form -> isValid())
{
    ...

    $path = isset($_GET['from-order']) ? "order/?continue" : "registration/complete/";
    $mv -> redirect($path);
}

404 Error

If the requested page can't be found in URL configurations (more details in General principle of templates section), then in MV an own page of 404 error will be shown. The included file is located in "views" folder and by default has "view-404.php" name. When redirecting to 404 page, an additional HTTP header will be sent "HTTP/1.1 404 Not Found".

The "display404()" method may also accept a parameter. If this parameter is positive, then the redirect won't occur.

//If the product not found, show 404 error
$content = $mv -> products -> findRecord(array("url" => "interesting-book", "active" => 1));
$mv -> display404($content);
 
//If the get the product ($content variable is not false), then continue to display the page