php8.5
Home/ Manual/ yaf / yaf_response_abstract/ Yaf_Response_Abstract::setRedirect

Yaf_Response_Abstract::setRedirect

PHP function Edit on GitHub ✎

(Yaf >=1.0.0)

Redirect to another URL

Description

Yaf_Response_Abstract::setRedirect(string $url): bool|null

Redirect the client to another URL (sends a Location header).

Parameters

url

The URL to redirect to.

Return Values

Returns true on success, or null on failure.

Examples

Yaf_Response_Abstract::setRedirect example

php
<?php
class AccountController extends Yaf_Controller_Abstract
{
    public function indexAction()
    {
        if (!Yaf_Session::getInstance()->has("login")) {
            /* send a Location header pointing to the login page */
            $this->getResponse()->setRedirect("/account/login");
            return false; // nothing to render here
        }
    }
}
?>

See Also

  • Yaf_Controller_Abstract::redirect

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