php8.5
Home/ Manual/ yaf / yaf_controller_abstract/ Yaf_Controller_Abstract::redirect

Yaf_Controller_Abstract::redirect

PHP function Edit on GitHub ✎

(Yaf >=1.0.0)

Redirect to a URL

Description

Yaf_Controller_Abstract::redirect(string $url): bool|null

Redirects the client to another URL by sending a Location header (HTTP status 302).

Parameters

url

The URL to redirect to.

Return Values

Returns true on success, or false / null on failure.

Examples

Yaf_Controller_Abstract::redirect example

php
<?php
class AccountController extends Yaf_Controller_Abstract
{
    public function loginAction() {
        if (!$this->getRequest()->getParam("user")) {
            // send a Location header with HTTP status 302
            $this->redirect("http://www.example.com/account/login/");
            return false; // skip auto-rendering
        }
    }
}
?>

See Also

  • Yaf_Controller_Abstract::forward
  • Yaf_Response_Abstract::setRedirect

Source: reference/yaf/yaf_controller_abstract/redirect.xml · from the official PHP manual (php/doc-en)